Plot function only plots one coordinate
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Tomas White
il 8 Feb 2022
Commentato: Star Strider
il 9 Feb 2022
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 Commenti
Risposta accettata
Star Strider
il 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 Commenti
Più risposte (1)
David Hill
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
