How to pick out the details of a specific line in an iterative graph?
1 view (last 30 days)
Show older comments
Hello,
I wrote this code to plot different paths of a projectile when shot of at the same initial velocity but different angles. Want I'd like to do is mark the path of the of the projectile that goes the farthest. Currently all the lines are blue and I can't tell which one goes the farthest and what angle it was shot from. I've been trying to identify which projectile goes the farthest and what angle it was shot from but I can't figure out how to do that. Any help would be great!
%Projectile motion
%Initial Conditions
v0= 13; % Initial Velocity
a= 0:5:70; % iteration of launch angles
h= 0.02; % Time step
a=a*pi/180;
g=9.8; %acceleration due to gravity in m/s^2
%td=2*v0*sin(a)/g; %total time
x1=0;
y1=0;
figure('color','white');
for t=0:h:3+h
plot(x1,y1,'bo')
hold all
xlim([0 20]);
ylim([0 15]);
title('Projectile Motion');
xlabel('Distance in meter');
ylabel('Height in meter');
getframe;
x1=x1+h*v0*cos(a); %Euler's method for x
y1=y1+h*(v0*sin(a)-g*t);%Euler's method for y
end
0 Comments
Accepted Answer
jonas
on 1 Sep 2018
Try this instead. It's faster and you store everything for easier post-processing of results.
%Projectile motion
%Initial Conditions
v0= 13; % Initial Velocity
a= 0:5:70; % iteration of launch angles
h= 0.02; % Time step
a=a*pi/180;
g=9.8; %acceleration due to gravity in m/s^2
%td=2*v0*sin(a)/g; %total time
ts=h;
tend=3+h;
x1=nan(length(0:ts:tend),length(a))
y1=nan(length(0:ts:tend),length(a))
% Initial vals
x1(1,:)=0;
y1(1,:)=0;
t=0:ts:tend;
for i=1:length(t)
x1(i+1,:)=x1(i,:)+h*v0*cos(a); %Euler's method for x
y1(i+1,:)=y1(i,:)+h*(v0*sin(a)-g*t(i));%Euler's method for y
end
figure('color','white');
title('Projectile Motion');
xlabel('Distance in meter');
ylabel('Height in meter');
plot(x1,y1,'bo')
xlim([0 20]);
ylim([0 15]);
[mavxal,ind]=max(x1(:))
5 Comments
jonas
on 3 Sep 2018
Then you've been out of luck! I'll take a look and see if there is anything I can answer.
Many times people just move on with their life after getting an answer, which is understandable but annoying sometimes :)
Walter Roberson
on 3 Sep 2018
Our goal here is not to write people's code for them, so it is not uncommon that we do not provide direct answers to people's questions. Instead, we try to help people understand MATLAB so they can figure out the answers to their questions.
Also, it is difficult for us to completely answer questions when you fail to respond with necessary information, such as https://www.mathworks.com/matlabcentral/answers/387388-error-with-part-of-code-for-mri-enhancement?s_tid=prof_contriblnk#comment_543849
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!