Matlab中二阶常微分方程的求解系统 [英] Solving System of Second Order Ordinary Differential Equation in Matlab

查看:395
本文介绍了Matlab中二阶常微分方程的求解系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

我正在使用Matlab通过使用ODE45数值求解二阶常微分方程组的系统来模拟一些动力学系统.我从Mathworks中找到了很棒的教程(末尾为教程的链接),以了解如何执行此操作.

I am using Matlab to simulate some dynamic systems through numerically solving systems of Second Order Ordinary Differential Equations using ODE45. I found a great tutorial from Mathworks (link for tutorial at end) on how to do this.

在本教程中,方程式系统在x和y中是显式的,如下所示:

In the tutorial the system of equations is explicit in x and y as shown below:

x''=-D(y) * x' * sqrt(x'^2 + y'^2)
y''=-D(y) * y' * sqrt(x'^2 + y'^2) + g(y)

以上两个方程的形式均为y''= f(x,x',y,y')

Both equations above have form y'' = f(x, x', y, y')

问题

但是,我遇到的方程组系统中,如示例所示,无法明确求解变量.例如,其中一个系统具有以下3组二阶常微分方程:

However, I am coming across systems of equations where the variables can not be solved for explicitly as shown in the example. For example one of the systems has the following set of 3 second order ordinary differential equations:

y双素数方程

y'' - .5*L*(x''*sin(x) + x'^2*cos(x) + (k/m)*y - g = 0

x双素数方程

.33*L^2*x'' - .5*L*y''sin(x) - .33*L^2*C*cos(x) + .5*g*L*sin(x) = 0

一个素数是一阶导数 双素数是二阶导数 L,g,m,k和C是给定的参数.

A single prime is first derivative A double prime is second derivative L, g, m, k, and C are given parameters.

如何使用Matlab数值求解一组不能明确求解二阶的二阶常微分方程?

How can Matlab be used to numerically solve a set of second order ordinary differential equations where second order can not be explicitly solved for?

谢谢!

推荐答案

第二个系统的格式为

a11*x'' + a12*y'' = f1(x,y,x',y')
a21*x'' + a22*y'' = f2(x,y,x',y')

您可以将其求解为线性系统

which you can solve as a linear system

[x'', y''] = A\f

,或者在这种情况下,明确使用克莱默规则

or in this case explicitly using Cramer's rule

x'' = ( a22*f1 - a12*f2 ) / (a11*a22 - a12*a21)

y''相应.

我强烈建议将中间变量保留在代码中,以减少键入错误的机会,并避免对同一表达式进行多次计算.

I would strongly recommend leaving the intermediate variables in the code to reduce chances for typing errors and avoid multiple computation of the same expressions.

代码可能看起来像这样(未经测试)

Code could look like this (untested)

function dz = odefunc(t,z)
    x=z(1); dx=z(2); y=z(3); dy=z(4);
    A = [  [-.5*L*sin(x),  1] ;  [.33*L^2,  -0.5*L*sin(x)]  ]
    b = [ [dx^2*cos(x) + (k/m)*y-g]; [-.33*L^2*C*cos(x) + .5*g*L*sin(x)] ]

    d2 = A\b

    dz = [ dx, d2(1), dy, d2(2) ]
end

这篇关于Matlab中二阶常微分方程的求解系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆