Splitting a position vector into X & Y then plotting them
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Allen
am 24 Aug. 2020
Beantwortet: Alan Stevens
am 24 Aug. 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 Kommentare
Akzeptierte Antwort
Alan Stevens
am 24 Aug. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!