簡體   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