Splitting a position vector into X & Y then plotting them
7 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Alan Stevens
2020 年 8 月 24 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!