フィルターのクリア

Retrieving 2nd derivative after solving second order ODE via ode45

6 ビュー (過去 30 日間)
Chinmay Sridhar
Chinmay Sridhar 2018 年 8 月 28 日
コメント済み: Torsten 2023 年 3 月 30 日
I have solved a simple pendulum problem (a pendulum driven by a motor at the joint), using ode45. I first defined the function in terms of the state space variables in a file called function1dof.m:
function func = F(t,x)
m = 1;
g = 10;
L = 1; Lc = L/2;
I = 0.3333; % kg-m^2
u = 3.8; % Torque in N-m
func = zeros(2,1);
func(1) = x(2);
func(2) = (3/(m*(L^2)))*(u - m*g*Lc*sin(x(1)));
end
Then, I called this function in another script called solver1dof.m:
t0 = 0; tf = 5;
x10 = 0; x20 = 0;
[t,x] = ode45(@function1dof,[t0,tf],[x10,x20]);
However, when I defined my states such that the system is a first order ODE (so that ode45 would solve it), I realized the output gives the 0th and 1st derivatives, and not the 2nd derivatives. Is there some way I could calculate the 2nd derivative of the angle in this pendulum problem? (Note: The independent variable in this problem is the angle of the pendulum).

採用された回答

Torsten
Torsten 2018 年 8 月 29 日
t0 = 0; tf = 5;
x10 = 0; x20 = 0;
[t,x] = ode45(@function1dof,[t0,tf],[x10,x20]);
for i=1:numel(t)
t_actual = t(i);
x_actual = x(i,:);
ders = function1dof(t_actual,x_actual);
second_derivative(i) = ders(2);
end
plot(t,second_derivative)
Best wishes
Torsten.
  3 件のコメント
Siddharth Jain
Siddharth Jain 2023 年 3 月 30 日
I have 6 DOF, how can this be modified for that?
Torsten
Torsten 2023 年 3 月 30 日
The derivatives of your solution variables can be retrieved after integration by
[t,y] = ode45(@fcn,tspan,y0);
y_derivatives = zeros(size(y));
for i=1:numel(t)
t_actual = t(i);
y_actual = y(i,:);
y_derivatives(i,:) = fcn(t_actual,y_actual).';
end
plot(t,y_derivatives)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by