Matlab微分方程符号解和数值解

19 篇文章 5 订阅

符号解用dsolve函数
例 求微分方程 y′′+4y+4y=e2x

 dsolve('D2y+4*Dy+4*y=exp(-2*x)')

结果

ans =

1/(4*exp(2*x)) + C5/exp(2*t) + (C6*t)/exp(2*t)

例 求解微分方程 x2y+xy=y2,y(1)=1 的特解

dsolve('x^2*Dy+x*y=y^2','y(1)=1')

结果

ans =

-(x*(tan(-(x*((- 1 + 2*x*atan((2*i)/x - i)*i)/x^2 + t/x^2)*i)/2) + i)*i)/2

数值解用龙格库塔方法
函数
[X,Y]=ode23(f,[x0,xn],y0)
[X,Y]=ode45(f,[x0,xn],y0)
f是函数, y0 是初值, [x0,xn] 是区间
ode23是二阶三阶龙格库塔方法,ode45是四阶五阶龙格库塔方法
例 求微分方程

dydx=3y+2xy(0)=1

在[1,3]区间内的数值解。
f.m

function f=f(x,y)
f=-3.*y+2.*x;
end

输入命令

[X,Y]=ode45('f',[1 3],1);
X',Y'

结果

ans =

  Columns 1 through 8

    1.0000    1.0500    1.1000    1.1500    1.2000    1.2500    1.3000    1.3500

  Columns 9 through 16

    1.4000    1.4500    1.5000    1.5500    1.6000    1.6500    1.7000    1.7500

  Columns 17 through 24

    1.8000    1.8500    1.9000    1.9500    2.0000    2.0500    2.1000    2.1500

  Columns 25 through 32

    2.2000    2.2500    2.3000    2.3500    2.4000    2.4500    2.5000    2.5500

  Columns 33 through 40

    2.6000    2.6500    2.7000    2.7500    2.8000    2.8500    2.9000    2.9500

  Column 41

    3.0000


ans =

  Columns 1 through 8

    1.0000    0.9559    0.9226    0.8987    0.8827    0.8735    0.8703    0.8722

  Columns 9 through 16

    0.8785    0.8885    0.9017    0.9178    0.9363    0.9568    0.9791    1.0030

  Columns 17 through 24

    1.0282    1.0545    1.0818    1.1099    1.1388    1.1683    1.1983    1.2287

  Columns 25 through 32

    1.2596    1.2908    1.3224    1.3541    1.3861    1.4183    1.4506    1.4831

  Columns 33 through 40

    1.5157    1.5484    1.5812    1.6140    1.6470    1.6799    1.7130    1.7460

  Column 41

    1.7792

例 求微分方程

5dydx+y=1y(0)=2

的数值解。
f.m

function f=f(x,y)
f=-y./5+1/5;
end

输入命令

[X,Y]=ode45('f',[1 3],2);
X',Y'

结果

ans =

  Columns 1 through 8

    1.0000    1.0500    1.1000    1.1500    1.2000    1.2500    1.3000    1.3500

  Columns 9 through 16

    1.4000    1.4500    1.5000    1.5500    1.6000    1.6500    1.7000    1.7500

  Columns 17 through 24

    1.8000    1.8500    1.9000    1.9500    2.0000    2.0500    2.1000    2.1500

  Columns 25 through 32

    2.2000    2.2500    2.3000    2.3500    2.4000    2.4500    2.5000    2.5500

  Columns 33 through 40

    2.6000    2.6500    2.7000    2.7500    2.8000    2.8500    2.9000    2.9500

  Column 41

    3.0000


ans =

  Columns 1 through 8

    2.0000    1.9900    1.9802    1.9704    1.9608    1.9512    1.9418    1.9324

  Columns 9 through 16

    1.9231    1.9139    1.9048    1.8958    1.8869    1.8781    1.8694    1.8607

  Columns 17 through 24

    1.8521    1.8437    1.8353    1.8270    1.8187    1.8106    1.8025    1.7945

  Columns 25 through 32

    1.7866    1.7788    1.7711    1.7634    1.7558    1.7483    1.7408    1.7334

  Columns 33 through 40

    1.7261    1.7189    1.7118    1.7047    1.6977    1.6907    1.6839    1.6771

  Column 41

    1.6703
  • 8
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值