From: Walter Roberson on
Matt Fig wrote:
> An example:
>
> % Data
> x = -10:.1:10;
> y = -(x+2).^2+3;
>
> % Engine
> [loc,loc] = max(y);
> plot(x,y,'-b',x(loc),y(loc),'*r')

If I recall the OP wanted to find all of the locations at which the
maximum occurred; the above code will only find the first location.

I suggest that the original poster refer to find() in combination with
max().
From: Matt Fig on
Walter Roberson <roberson(a)hushmail.com> wrote in message <7945o.46038$dx7.2257(a)newsfe21.iad>...
> Matt Fig wrote:
> > An example:
> >
> > % Data
> > x = -10:.1:10;
> > y = -(x+2).^2+3;
> >
> > % Engine
> > [loc,loc] = max(y);
> > plot(x,y,'-b',x(loc),y(loc),'*r')
>
> If I recall the OP wanted to find all of the locations at which the
> maximum occurred; the above code will only find the first location.
>
> I suggest that the original poster refer to find() in combination with
> max().

Except that this is a ballistic problem with only one max as I understand it. For example, the OP's code could be cleaned up to give the same results as:




function Trajectory(angle,V,p)
% trajectory: function to solve trajectory motion with inputs of angle
% velocity, and position. This function will also give trajectory for
% the alternate angular value. Or +180 degrees.
%
% y = trajectory_motion(angle,V,p)
%
% angle = Angle of trajectory
% V = Velocity
% p = Position from x-axis.
%
% Inputs: Angle in degrees,Velocity in m/s, point of elevation in m.

G = 9.8; %Gravity (earth)
t = 0:.01:1000; %# of Calculations
% math/graphics
f = t*V*cosd(angle); %Flight "X component"
h1 = p+t*V*sind(angle) - 1/2*G*t.^2; %Height1 "Y component"
figure
plot(f,h1,'-');
hold on;
set(gca,'ylim',[0,max(h1)+(max(h1)/4)]) %Graphical restrictions
xlabel('Distance (m)'); ylabel('Height (m)'); %Ladbels
% heightmax = max(h1); %max height
% distance = (V.^2*sind(2.*angle))/G; %Distance of flight
a = 1:0.1:45;
x = t*V*cosd(a(end)); %angle
%Plots and annotation
h2 = p+t*V*sind(angle) - 1/2*G*t.^2; %alternate angle with same max height
plot(x,h2,'-r');
[loc,loc] = max(h1);
plot(f(loc),h1(loc),'*k','markersize',12)
box off;
grid on; %graphics
legend('Original Trajectory Angle','Alternate Trajectory Angle',2); %legend
text(x(loc),h1(loc)*1.1,... %annotation
'maximum height','FontSize',8)
title(sprintf('approx. max height = %-6.0f m\n', max(h1))) %title with
%max height
From: Walter Roberson on
Matt Fig wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message
> <7945o.46038$dx7.2257(a)newsfe21.iad>...
>> Matt Fig wrote:
>> > An example:
>> > > % Data
>> > x = -10:.1:10;
>> > y = -(x+2).^2+3;
>> > > % Engine
>> > [loc,loc] = max(y);
>> > plot(x,y,'-b',x(loc),y(loc),'*r')
>> If I recall the OP wanted to find all of the locations at which the
>> maximum occurred; the above code will only find the first location.
>>
>> I suggest that the original poster refer to find() in combination with
>> max().
>
> Except that this is a ballistic problem with only one max as I
> understand it. For example, the OP's code could be cleaned up to give
> the same results as:

That's what I get for reading postings too early in the morning and
going on memory. It was Mustaf's thread (answered by Bruno) that
involved potential multiple maximums.
First  |  Prev  | 
Pages: 1 2
Prev: Error
Next: face color database