How to Get Second Derivative in ode45 solver?

16 次查看(过去 30 天)
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

采纳的回答

Sam Chak
Sam Chak 2022-7-21
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')
  1 个评论
ercan duzgun
ercan duzgun 2022-7-25
Dear @Sam Chak thank you very much for your response. Really, you are right, it was really the elephant in the room :) . I am surprised how I didn't notice this very obvious thing. Thank you for showing me, explaining me in detailed.
Kind regards,
Ercan

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by