在Matlab中从ode45返回原始数学函数值?

在Matlab中从ode45返回原始数学函数值?,matlab,function,Matlab,Function,我的目的是从下面的二阶微分方程中绘制原始数学函数值: I(thetadbldot)+md(g-o^2asin(ot))sin(theta)=0 其中,thetadbldot是theta相对于t的二阶导数,m、d、I、g、a、o为常数。初始条件为theta(0)=pi/2和thetadot(0)=0 我的问题是,我的知识和指导仅限于存储导数的值并返回它们,而不是方程中原始数学函数的值。下面你可以看到一个代码,它以柯西形式计算微分,并给出导数。有人有什么建议吗?谢谢 function xdot =

我的目的是从下面的二阶微分方程中绘制原始数学函数值:

I(thetadbldot)+md(g-o^2asin(ot))sin(theta)=0

其中,
thetadbldot
theta
相对于
t
的二阶导数,
m、d、I、g、a、o
为常数。初始条件为
theta(0)=pi/2
thetadot(0)=0

我的问题是,我的知识和指导仅限于存储导数的值并返回它们,而不是方程中原始数学函数的值。下面你可以看到一个代码,它以柯西形式计算微分,并给出导数。有人有什么建议吗?谢谢

function xdot = penduluma(t,x)
% The function penduluma(t,x) calculates the differential 
% I(thetadbldot)+md(g-o^2asin(ot))sin(theta)=0 where thetadbldot is the second 
% derivative of theta with respect to t and m,d,I,g,a,o are given constants.
% For the state-variable form, x1=theta and x2=thetadot. x is a 2x1 vector on the form
% [theta,thetadot].
m=1;d=0.2;I=0.1;g=9.81;a=0.1;o=4;
xdot = [x(2);m*d*(o^2*a*sin(o*t)-g)*sin(x(1))/I];
end


获得角度后,可以使用以下公式计算角速度和加速度:

给出了以下倍频程图(在MATLAB中应相同):

或者,您可以使用原始微分方程来计算:

x_ddot = -m*d*(o^2*a*sin(o*t)-g).*sin(xa(:,1))/I;
这给出了类似的结果:


我方可能对ode45作为xa返回的内容有误解。我开始倾向于x1和x2,而不是x1dot和x2dot。
options=odeset('RelTol', 1e-6);
[t,xa]=ode45(@penduluma,[0,20],[pi/2,0],options);
x_ddot = zeros(size(t));
x_ddot(2:end) = diff(xa(:,2))./diff(t);
plot(t,xa,t,x_ddot)
legend('angle','angular velocity','angular acceleration')
x_ddot = -m*d*(o^2*a*sin(o*t)-g).*sin(xa(:,1))/I;