声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1319|回复: 5

[编程技巧] 大家讨论一下这个四阶龙格库塔法解微分方程

[复制链接]
发表于 2006-10-2 19:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
例15.3.2  利用上述程序求解初值问题: ,积分区间为 。
解:先用m文件先定义一个名为f1531.m的函数文件。
        function z = f1531(x)
      z = y – 2*x/y;
建立一个主程序prog1531.m
        clc
    clear all
rk4('f1531',0,1,1,10)

    然后在MATLAB命令窗口运行上述主程序,即:
    >> prog1531
按照这样的步骤,做不出来

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2006-10-3 08:44 | 显示全部楼层
function z = f1531(x)
      z = y – 2*x/y;
这是微分方程??
 楼主| 发表于 2006-10-3 11:04 | 显示全部楼层
原题是y‘=y-2x/y,y(0)=1,(0〈x〈1)
发表于 2006-10-3 11:39 | 显示全部楼层
>> fun=inline('y-2*x./y','x','y');
>> [x,y]=ode45(fun,[0 1],1);[x',y']
ans =

  Columns 1 through 8

         0    0.0250    0.0500    0.0750    0.1000    0.1250    0.1500    0.1750

  Columns 9 through 16

    0.2000    0.2250    0.2500    0.2750    0.3000    0.3250    0.3500    0.3750

  Columns 17 through 24

    0.4000    0.4250    0.4500    0.4750    0.5000    0.5250    0.5500    0.5750

  Columns 25 through 32

    0.6000    0.6250    0.6500    0.6750    0.7000    0.7250    0.7500    0.7750

  Columns 33 through 40

    0.8000    0.8250    0.8500    0.8750    0.9000    0.9250    0.9500    0.9750

  Columns 41 through 48

    1.0000    1.0000    1.0247    1.0488    1.0724    1.0954    1.1180    1.1402

  Columns 49 through 56

    1.1619    1.1832    1.2042    1.2247    1.2450    1.2649    1.2845    1.3038

  Columns 57 through 64

    1.3229    1.3416    1.3601    1.3784    1.3964    1.4142    1.4318    1.4491

  Columns 65 through 72

    1.4663    1.4832    1.5000    1.5166    1.5330    1.5492    1.5652    1.5811

  Columns 73 through 80

    1.5969    1.6125    1.6279    1.6432    1.6583    1.6733    1.6882    1.7029

  Columns 81 through 82

    1.7176    1.7321
要是想画图,用下面的命令:
plot(x,y)
发表于 2006-10-3 11:41 | 显示全部楼层
>> f1531=inline('x-2*t/x','t','x');
>> rk4('f',0,1,1,10)

ans =

         0    1.0000
    0.1000    1.0000
    0.2000    1.0000
    0.3000    1.0000
    0.4000    1.0000
    0.5000    1.0000
    0.6000    1.0000
    0.7000    1.0000
    0.8000    1.0000
    0.9000    1.0000
    1.0000    1.0000
 楼主| 发表于 2006-10-3 15:11 | 显示全部楼层
谢谢了!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-10-4 03:24 , Processed in 0.061520 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表