Splitting a position vector into X & Y then plotting them

7 ビュー (過去 30 日間)
Michael Allen
Michael Allen 2020 年 8 月 24 日
回答済み: Alan Stevens 2020 年 8 月 24 日
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-');

採用された回答

Alan Stevens
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 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by