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 CenterFile Exchange에서 Creating, 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