How to find velocity and position of this ODE

7 ビュー (過去 30 日間)
Lawrence Arabia
Lawrence Arabia 2019 年 1 月 25 日
コメント済み: madhan ravi 2019 年 1 月 25 日
Hello all.
I've been trying to find the velocity and position of an object with an accelration rate of a(x)=-2x+1 m/s^2 with the initial conditions of v(0) = 4 m/s, and x(0) = 5 m, all at a time of 5 seconds.. I did my code on it, and believed to have found position with my current plot, however I can't seem to figure out how to calculate and plot my x versus t graph for velocity. Can someone help me out please?
Code below:
[T,s]=ode45(@eom,linspace(0,5,101),[5,4]);
plot(T,s(:,l),'-k')
xlabel('Time, sec')
ylabel('x,m')
function ds=eom(T,s)
ds(1,1)=s(2)
ds(2,1)=-2*s(1)+1
end
%Above function was for position, which seems to work.
%Below was my attempt at the velocity plot.
function ds=eom(T,s)
ds(1,1)=s(2)
ds(2,1)=-2*s(2)^2+s(1)_
end

回答 (1 件)

David Goodmanson
David Goodmanson 2019 年 1 月 25 日
Hi Peter,
since you have defined s(2) = ds(1)/dt, s(2) is the velocity function already. No more work required, exceptto plot it,
[T,s]=ode45(@eom,linspace(0,5,101),[5,4]);
plot(T,s)
xlabel('Time, sec')
legend('x, m','v ,m/s','location','southeast')
function ds=eom(T,s)
ds(1,1)=s(2)
ds(2,1)=-2*s(1)+1
end
Here the plot function plots out the colums of s independently, so you get x and v.
  1 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 25 日
ode45 with no output arguments plots by default thereby avoiding the plot call.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by