Plot function only plots one coordinate
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tomas White
le 8 Fév 2022
Commenté : Star Strider
le 9 Fév 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 commentaires
Réponse acceptée
Star Strider
le 8 Fév 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 commentaires
Plus de réponses (1)
David Hill
le 8 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
