Plotting 3 for loops at once.
Show older comments
I am trying to create a for loop that goes through the loop with values theta 0 through 15. There is a value v_perp defined in the loop, and I want the plot to be of theta on the x axis and v_perp on the y. I am able to get all 3 to plot at the same time but there is one point for each loop that is way off from the other points and I am not sure why. Here is my code so far:
v_min = 16.5;
v_avg = 18;
v_max = 19.5;
x_r = 21.45;
y_r = 1.265;
for theta = 0:15
A = -9.81/2;
B = (v_min*sin(30))+(v_min*cos(30)*tan(theta));
C = 1.265+21.45*(tan(theta));
y = [A B C];
t = roots(y);
t_first = t(1);
v_perp(theta+1) = (-sind(-theta)*(16.5*cosd(30)))+(cosd(-theta)*((-9.81*t_first)+(16.5*cosd(30))));
v_tot = sqrt((16.5*cosd(30)).^2+(((-9.81*t)+(16.5*cosd(30)))).^2);
if v_perp(theta+1) > 0.4*v_tot
point(theta+1) = true;
else
point(theta+1) = false;
end
end
v_perp(~point) = nan;
theta = 0:15;
plot(theta,v_perp,'r.','MarkerSize',15)
hold on
for theta = 0:15
A = -9.81/2;
B = (v_max*sin(30))+(v_max*cos(30)*tan(theta));
C = 1.265+21.45*(tan(theta));
y = [A B C];
t = roots(y);
t_first = t(1);
v_perp2(theta+1) = (-sind(-theta)*(16.5*cosd(30)))+(cosd(-theta)*((-9.81*t_first)+(16.5*cosd(30))));
v_tot = sqrt((16.5*cosd(30)).^2+(((-9.81*t)+(16.5*cosd(30)))).^2);
if v_perp2(theta+1) > 0.4*v_tot
point(theta+1) = true;
else
point(theta+1) = false;
end
end
v_perp2(~point) = nan;
theta = 0:15;
plot(theta,v_perp2,'b.','MarkerSize',15)
hold on
for theta = 0:15
A = -9.81/2;
B = (v_avg*sin(30))+(v_avg*cos(30)*tan(theta));
C = 1.265+21.45*(tan(theta));
y = [A B C];
t = roots(y);
t_first = t(1);
v_perp3(theta+1) = (-sind(-theta)*(16.5*cosd(30)))+(cosd(-theta)*((-9.81*t_first)+(16.5*cosd(30))));
v_tot = sqrt((16.5*cosd(30)).^2+(((-9.81*t)+(16.5*cosd(30)))).^2);
if v_perp3(theta+1) > 0.4*v_tot
point(theta+1) = true;
else
point(theta+1) = false;
end
end
v_perp3(~point) = nan;
theta = 0:15;
plot(theta,v_perp3,'k.','MarkerSize',15)
disp(theta)
disp(t)
disp(v_perp)
disp(v_tot)
Answers (0)
Categories
Find more on Triangulations 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!