I am trying to create a plot for certain values.
Show older comments
I am trying to create a plot for certain values. I am having troubles defining my range as well as creating the correct plot. 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 only want it to plot values if v_perp is <= 0.4*v_tot. What I have so far is below:
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);
v_perp = (-sin(-theta)*(16.5*cos(30)))+(cos(-theta)*((-9.81*t)+(16.5*cos(30))));
v_tot = sqrt((16.5*cos(30)).^2+(((-9.81*t)+(16.5*cos(30)))).^2);
end
%plot(theta,v_perp,'-r')
disp(theta) disp(t) disp(v_perp) disp(v_tot)
Answers (1)
Image Analyst
on 5 Mar 2017
Try this:
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*sind(30))+(v_min*cosd(30)*tand(theta));
C = 1.265+21.45*(tand(theta));
y = [A B C];
t = roots(y); % HAS 2 VALUES!!! Use the first one.
t_to_use = t(1);
v_perp(theta+1) = (-sind(-theta)*(16.5*cosd(30)))+(cosd(-theta)*((-9.81*t_to_use)+(16.5*cosd(30))));
v_tot = sqrt((16.5*cosd(30)).^2+(((-9.81*t_to_use)+(16.5*cosd(30)))).^2);
% Store whether this point is to be plotted.
if v_perp(theta+1) > v_tot
keepit(theta+1) = true;
else
keepit(theta+1) = false;
end
end
keepit
% Set rows not to keep to nan so they won't be plotted.
v_perp(~keepit) = nan;
theta = 0:15
plot(theta,v_perp, 'r-.', 'MarkerSize', 15)
but none of the v_perp values is ever greater than the v_Tot values. Also note I changed to the degree version of trig functions, like cosd() instead of cos(), and I'm using just one of the two t values.
Categories
Find more on Material Sciences 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!