필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by