How to find velocity and position of this ODE

34 visualizaciones (últimos 30 días)
Lawrence Arabia
Lawrence Arabia el 25 de En. de 2019
Comentada: madhan ravi el 25 de En. de 2019
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

Respuestas (1)

David Goodmanson
David Goodmanson el 25 de En. de 2019
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 comentario
madhan ravi
madhan ravi el 25 de En. de 2019
ode45 with no output arguments plots by default thereby avoiding the plot call.

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by