MATLAB:用matlab求解非线性二阶ode系统

时间:2017-01-11 19:53:40

标签: matlab ode differential-equations

我有以下方程系统

enter image description here

用matlab的ode45可以解决这个问题吗?我知道我需要将二阶方程转换为两个一阶方程,但我的混淆来自于 s theta 的衍生产品。 / p>

P.S。 Beta只是一个常数

我将方程组定义为函数:

function dy = pend(t,y)
beta = 1;
dy(1) = y(2);
dy(2) = -1/(1+y(3))*sin(y(1))-2/(1+y(3))*y(2)*y(4);
dy(3) = y(4);
dy(4) = (1+y(3))*y(2)*y(2)+cos(y(1))-1-beta^2*y(3);
y=y';
end

将y(1)视为theta,y(2)为theta的导数,y(3)为 s ,y(4)为其相对于时间的导数。

然后我用

解决它
[t,y] = ode45(@pend,[0 20],[pi/4 ; 0 ; 0 ; 0]);

1 个答案:

答案 0 :(得分:1)

是的,应该可以使用ode45来解决。

theta    = x1
s        = x2 
thetadot = x3 
sdot     = x4

然后你将得到以下方程组:

x1dot = x3
x2dot = x4
x3dot + sin(x1)/(1 + x2) + 2/(1+x2).x4.x3 = 0
x4dot - (1 + x2).(x3)^2 = cos(x1)-1-beta^2*x2

现在为ode45提供这些方程组,其中包含x1x2x3x4的初始值。您需要适当地重写3 rd 和4 th 等式。

<强> EDIT1:

你已经编写了方程组。所以现在使用

y0    = [pi/4; 0; 0; 0];
tspan = [0 20];
[t,y] = ode45(pend, tspan, y0);

<强> EDIT2:

function dy = pend(t,y)

    beta = 1;

    dy = [y(2);
          -1 / (1 + y(3))*sin(y(1)) - 2/(1 + y(3))*y(2)*y(4);
           y(4);
           (1 + y(3))*y(2)*y(2) + cos(y(1)) - 1 - beta^2*y(3)];
end

这应该适合你。

相关问题