Plot function only plots one coordinate
1 view (last 30 days)
Show older comments
For my matlab introduction class Im trying to plot a graph by feeding it coordinates obtained by the (x =) and (y=) equations. The problem is that the obtained graph has no points on it; At the moment I dont know how to proceed.
clear
clc
fprintf('Parabolic motion 1\n');
fprintf(1,'Provide an input for the following constants\n');
V0 = input('Initial velocity = ');
b0 = input('Angle = ');
C = input('"C" = Proyectile mass / air resistance coefficient = ');
t = input('Number of desired plotted points = ');
vy = V0*cosd(b0)
vx = V0*sind(b0)
x=0
y=0
i=0
while (i <= t)
x= C * vx * (1-2.718^(-(i)/C));
y= (C * vy + 9.8 * ((C)^2))*(1-2.718^(-(i)/C))-9.8 * C * (i);
disp(x)
disp(y)
plot(x,y)
xlabel('Traveled distance (m)')
ylabel('Altitude (m)')
i++ ;
end
If anyone has a few minutes to take a look at this, I'd really appreciate it. I can't seem to find a solution. Thank you!
0 Comments
Accepted Answer
Star Strider
on 8 Feb 2022
MATLAB does not use C increment syntax.
One approach would be to subscript them and plot them at the end. That is definitely the more efficient approach.
% clear
% clc
fprintf('Parabolic motion 1\n');
fprintf(1,'Provide an input for the following constants\n');
% V0 = input('Initial velocity = ');
% b0 = input('Angle = ');
% C = input('"C" = Proyectile mass / air resistance coefficient = ');
% t = input('Number of desired plotted points = ');
V0 = 420;
b0 = 60;
C = pi;
t = 25;
vy = V0*cosd(b0)
vx = V0*sind(b0)
x=0
y=0
i=1
while (i <= t)
x(i) = C * vx * (1-2.718^(-(i)/C));
y(i) = (C * vy + 9.8 * ((C)^2))*(1-2.718^(-(i)/C))-9.8 * C * (i);
disp(x)
disp(y)
% plot(x,y)
% xlabel('Traveled distance (m)')
% ylabel('Altitude (m)')
i = i+1 ;
end
figure
plot(x,y)
grid
xlabel('Traveled distance (m)')
ylabel('Altitude (m)')
The disp calls in the loop are not necessary. It would be beter to display the stored values after the loop finishes.
.
2 Comments
More Answers (1)
David Hill
on 8 Feb 2022
fprintf('Parabolic motion 1\n');
fprintf(1,'Provide an input for the following constants\n');
V0 = input('Initial velocity = ');
b0 = input('Angle = ');
C = input('"C" = Proyectile mass / air resistance coefficient = ');
t = input('Number of desired plotted points = ');
T=linspace(0,10,t);%how long do you want (I assumed 10 seconds)
vy = V0*cosd(b0);
vx = V0*sind(b0);
x= C * vx * (1-2.718.^(-(T)/C));
y= (C * vy + 9.8 * ((C)^2))*(1-2.718.^(-(T)/C))-9.8 * C * T;
plot(x,y);
0 Comments
See Also
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!