how to plot 3 graphs with (+) sign convention?

2 views (last 30 days)
Charles
Charles on 28 Mar 2014
Hello... I am an mechanical engineering student learning MATLAB... I would like to know how can i graph 3 functions all done completely. I mean, when first graph meets condition of lower than 0, all the loops broken and other two graphs lies upper side of 0. I want all 3 graphs meet 0, and plot them on the figure... Help needed....T_T
% set random position of me and computer my_position = 50 * rand(1); com_position = 50 + 50 * rand(1);
% show where computer and i am plot(my_position, 0, 'go');hold on; plot(com_position, 0, 'mo');hold on;
% 10 chances to shoot for i = 1:10 % get speed and angle with my input cannon_angle = input('Input angle:'); cannon_speed = input('Input speed:');
% set 3 speeds, one with 2 degree up and another with 2 degree down
x_vel = cannon_speed * cosd(cannon_angle);
y_vel = cannon_speed * sind(cannon_angle);
x1_vel = cannon_speed * cosd(cannon_angle+2);
y1_vel = cannon_speed * sind(cannon_angle+2);
x2_vel = cannon_speed * cosd(cannon_angle-2);
y2_vel = cannon_speed * sind(cannon_angle-2);
t=0;
while (1)
% Vx = Vox;
% Vy = Voy - 9.81*t;
% Sx = Vox*t;
% Sy = Voy*t - 0.5*9.81*t^2
x_pos = my_position + x_vel * t;
y_pos = y_vel * t - 0.5*9.81*(t^2);
plot(x_pos, y_pos, 'ro'); hold on;
pause(0.01);
t = t + 0.01;
if y_pos<0
break;
end
x1_pos = my_position + x1_vel * t;
y1_pos = y1_vel * t - 0.5*9.81*(t^2);
plot(x1_pos, y1_pos, 'ks'); hold on;
pause(0.01);
t = t + 0.01;
if y1_pos<0
break;
end
x2_pos = my_position + x2_vel * t;
y2_pos = y2_vel * t - 0.5*9.81*(t^2);
plot(x2_pos, y2_pos, 'bd'); hold on;
pause(0.01);
t = t + 0.01;
if y2_pos<0;
break;
end
end
if abs(x1_pos - com_position) <3
sprintf('YOU GOT ME')
break;
elseif abs(x2_pos - com_position) <3
sprintf('YOU GOT ME')
break;
elseif abs(x_pos - com_position) <3
sprintf('YOU GOT ME')
break;
end
end
if i==10 disp('YOU FAILED'); end

Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!