大家讨论一下这个四阶龙格库塔法解微分方程
例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
按照这样的步骤,做不出来 function z = f1531(x)
z = y – 2*x/y;
这是微分方程?? 原题是y‘=y-2x/y,y(0)=1,(0〈x〈1) >> fun=inline('y-2*x./y','x','y');
>> =ode45(fun,,1);
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) >> 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 谢谢了!
页:
[1]