Can't plot a graph no matter what I do
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I have a college project and it involves plotting. I can't get the plot window to even open up despite I'm sure my code my code doesn't contain any mistakes.
Heres is the code:
clear
clc
disp('Welcome to the Projectilre Motion application')
%% error checking
% this code is for projectile motion using the following equations:
% v=u + at,v^2 = u^2 + 2as, s=ut+0.5 * at^2
disp('For the following questions, press 1 for yes and 2 for no');
check1 = input (' Does your projectile departure and landing zone share a similar height?: ');
check2 = input (' are you trying to clear a wall?: ');
check3 = input (' Is there an initial velocity?: ') ;
% error checking
%% request for inputs
if check1 == 1 && check2 ==2 && check3 ==1
u = input ('Please input the initial speed in m/s: ' );
angle = input ('Please input the initial direction in degrees: ');
ux = u.*cosd(angle);
uy = u.*sind(angle);
a = - 9.81;
% v=u + at,v^2 = u^2 + 2as, s=ut+0.5 * at^2;1/2ut^2 + ut - s = 0;
t1 = (-uy + sqrt (uy.^2-4*(1/2*uy)*0))/(a);
t2 = (-uy - sqrt (uy.^2-4*(1/2*uy)*0))/(a);
elseif check1 == 1 && check2 ==2 && check3 ==1
if t2 > t1
x = (0:1:10);
time = linspace2(0,t2,100);
Sy = uy*time + 1/2 * a .* time.^2;
Sx = ux*time;
plot(Sx,Sy, 'b-')
hold on
axis equal
end
댓글 수: 0
채택된 답변
Walter Roberson
2021년 1월 16일
편집: Walter Roberson
2021년 1월 19일
if check1 == 1 && check2 ==2 && check3 ==1
elseif check1 == 1 && check2 ==2 && check3 ==1
Those are the same conditions. You can only reach the elseif when the conditions are false for the if, but when they are false they cannot be true for the elseif because they are the same.
Note: reading your prompts, people are not going to know to enter 1 or 2
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!