Retrieving 2nd derivative after solving second order ODE via ode45
5 次查看(过去 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).
0 个评论
采纳的回答
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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!