Splitting a position vector into X & Y then plotting them
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Michael Allen
le 24 Août 2020
Réponse apportée : Alan Stevens
le 24 Août 2020
Below is a function of position for a Simple Rocket that is losing mass due to fuel, Thrust is constant and a few other variables. I believe the " f " is the Y component and the y is the input x component. I am trying to save to .dat file the X Vector and the Y Vector, and then plot an Y(t) vs X(t). I can't seem to figure out how to do so, can I get some help?
%y=[x;y;x';y']
f=@(t,y) [y(3:4);-1/(2*m)*rho*Cd*S*norm(y(3:4))*y(3:4)-[0;g]];
fps = 60;
tspan = 0:1/10:20;
% vx0=0.01; %X velocity initial
% vy0=1; %Y velocity initial
y0=[0;0;v0;v0]; %Position, Xi Yi X'i Yi
[t,y] = ode45(f,tspan,y0);
save HW7_10.dat y -ascii
save HW7_11.dat f -ascii
% figure
% plot(x,y)
% title('Y(t) vs. X(t)')
figure
title('Y(t) vs. X(t)')
plot([y(end) y], [f(end) f], 'r-');
0 commentaires
Réponse acceptée
Alan Stevens
le 24 Août 2020
Soething like this (needs your data to get a sensible solution):
m = 1; rho = 1; Cd = 1; S = 1; g = 9.8; % Replace with your values
f=@(t,y) [y(3:4);-1/(2*m)*rho*Cd*S*norm(y(3:4))*y(3:4)-[0;g]];
fps = 60;
tspan = 0:1/10:20;
vx0=0.01; %X velocity initial
vy0=1; %Y velocity initial
y0=[0;0;vx0;vy0]; %Position, Xi Yi X'i Yi
[t,y] = ode45(f,tspan,y0);
X = y(:,1);
Y = y(:,2);
plot(X,Y)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects 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!