繁体   English   中英

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

[英]Returning original mathematical function values from ode45 in Matlab?

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

I(thetadbldot)+md(go^2asin(ot))sin(theta)=0

其中thetadbldottheta关于t的二阶导数,并且m,d,I,g,a,o给出常数。 初始条件为theta(0)=pi/2thetadot(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

options=odeset('RelTol', 1e-6);
[t,xa]=ode45(@penduluma,[0,20],[pi/2,0],options);
% Then the desired vector from xa is plotted to t. As it looks now the desired 
% values are not found in xa however.

一旦有了角度,就可以使用diff计算角速度和加速度:

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')

在Octave中给出以下图表(在MATLAB中应该相同):

在此处输入图片说明

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

x_ddot = -m*d*(o^2*a*sin(o*t)-g).*sin(xa(:,1))/I;

得到类似的结果:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM