MATLAB Answers

Nawal
0

how to take the derivative for the retained value from ode45?

Asked by Nawal
on 31 Jul 2013
I'm using the ode45 to find the velocity, now I need to find the acceleration how can I take the derivative of the retained value.
My ode45 is:
[ts,xs]= ode45(@my_function,[0,10],[5,0])
Thanks in advance!

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Walter Roberson
on 31 Jul 2013

gradient(xs(1,:), ts(:))

  6 Comments

Richard,
gradient(xs(:,1), ts)
will work as well. The use of a coordinate vector instead of a scalar spacing is documented for the 2D case but not for the 1D case, but it works anyhow.
I stand corrected, good to know!
gradient uses a first order method when the spacing is not equidistant. You can use the faster method FEX: DGradient and some other equivalent tools from the FEX, which apply a 2nd order method to get more accurate results for the derivatives.

Sign in to comment.


Answer by Nawal
on 1 Aug 2013

Can I do something like
diff [ts,xs]

  0 Comments

Sign in to comment.