How to Get Second Derivative in ode45 solver?
16 views (last 30 days)
Show older comments
Dear MATLAB users;
I would like to solve a nonlinear equation using ode45. ode45 solver provides time (t), position (x), velocity (x_dot) .
I need acceleration , second derivative (x_dotdot). However, I can't get x_dotdot as output from ode45. I looked at the options/parameteres of ode45. I couldn't find there information about that.
I know that I can get x_dotdot, using x_dot numerically by subtraction of xdot(step n) and xdot(n+1 step), by typing extra codes. But I just wondered if it is possible to do it without writing codes? Is it possible to get second derivative (x_dotdot) of ode45 by using options in ode45?
Thanks in advance.
Ercan
0 Comments
Accepted Answer
Sam Chak
on 21 Jul 2022
You don't need to..., because you can see the elephant in the room (not sure if this is the correct metaphorical idiom; I'm not good at English idioms).
Say the system is given by .
f = @(t, x) [x(2); - 2*x(2) - x(1)];
[t, x] = ode45(f, [0 10], [1 0]);
xddot = - 2*x(:,2) - x(:,1); % the acceleration, second derivative (x_dotdot)
plot(t, xddot), grid on, xlabel('t')
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!