[英]Returning original mathematical function values from ode45 in Matlab?
我的意图是从下面的二阶微分方程绘制原始数学函数值:
I(thetadbldot)+md(go^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
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.