请教各位大侠,3*y'''+5*y''+6*sin(t)*y=cost,t[0 5] y(0)=0,用matlab中的ode45,ode23来算,怎么算?
初始值不是很充分还有y'、y''初值没给出,假设分别是1、3,试下:
function dydt=fun_004(t,y)
dydt=[y(2);y(3);(cos(t)-5*y(2)-6*sin(t)*y(1))/3];
新建文件:
clc,clear,clear al
t0=[0 5];
y_0=[0 1 3];
[t45,y45]=ode45(@fun_004,t0,y_0)
[t23,y23]=ode23(@fun_004,t0,y_0)
subplot(211)
plot(t45,y45(:,1),'-',t45,y45(:,2),'-.',t45,y45(:,3),'.')
legend('一阶导数','二阶导数','三阶导数')
subplot(212)
plot(t23,y23(:,1),'-',t23,y23(:,2),'-.',t23,y23(:,3),'.')
legend('一阶导数','二阶导数','三阶导数')
结果:
t45 =
0
0.0001
0.0001
0.0002
0.0002
0.0005
0.0007
0.0010
0.0012
0.0025
0.0037
0.0050
0.0062
0.0125
0.0188
0.0251
0.0313
0.0627
0.0941
0.1255
0.1569
0.2819
0.4069
0.5319
0.6569
0.7819
0.9069
1.0319
1.1569
1.2819
1.4069
1.5319
1.6569
1.7819
1.9069
2.0319
2.1569
2.2819
2.4069
2.5319
2.6569
2.7819
2.9069
3.0319
3.1569
3.2819
3.4069
3.5319
3.6569
3.7819
3.9069
4.0319
4.1569
4.2819
4.4069
4.5319
4.6569
4.7427
4.8285
4.9142
5.0000
y45 =
0 1.0000 3.0000
0.0001 1.0002 2.9999
0.0001 1.0003 2.9999
0.0002 1.0005 2.9998
0.0002 1.0006 2.9997
0.0005 1.0014 2.9994
0.0007 1.0021 2.9991
0.0010 1.0029 2.9987
0.0012 1.0036 2.9984
0.0025 1.0074 2.9967
0.0037 1.0111 2.9950
0.0050 1.0149 2.9933
0.0063 1.0187 2.9916
0.0127 1.0374 2.9829
0.0193 1.0561 2.9741
0.0260 1.0748 2.9650
0.0328 1.0934 2.9557
0.0686 1.1854 2.9064
0.1072 1.2758 2.8520
0.1487 1.3645 2.7924
0.1929 1.4511 2.7276
0.3948 1.7736 2.4156
0.6344 2.0513 2.0118
0.9053 2.2724 1.5098
1.1997 2.4244 0.9060
1.5080 2.4948 0.2004
1.8193 2.4707 -0.6021
2.1212 2.3406 -1.4886
2.3998 2.0957 -2.4367
2.6403 1.7304 -3.4153
2.8273 1.2427 -4.3843
2.9459 0.6365 -5.2969
2.9819 -0.0774 -6.1004
2.9231 -0.8819 -6.7402
2.7591 -1.7531 -7.1635
2.4831 -2.6616 -7.3255
2.0931 -3.5726 -7.1944
1.5915 -4.4479 -6.7529
0.9848 -5.2482 -6.0036
0.2842 -5.9365 -4.9700
-0.4938 -6.4805 -3.6977
-1.3292 -6.8540 -2.2520
-2.1995 -7.0401 -0.7149
-3.0809 -7.0326 0.8234
-3.9498 -6.8377 2.2693
-4.7838 -6.4724 3.5307
-5.5627 -5.9658 4.5252
-6.2708 -5.3554 5.1876
-6.8984 -4.6849 5.4743
-7.4414 -4.0026 5.3632
-7.9012 -3.3595 4.8566
-8.2851 -2.8043 3.9781
-8.6072 -2.3799 2.7698
-8.8865 -2.1232 1.2888
-9.1461 -2.0653 -0.3961
-9.4122 -2.2277 -2.2119
-9.7129 -2.6216 -4.0868
-9.9543 -3.0273 -5.3704
-10.2352 -3.5420 -6.6259
-10.5649 -4.1624 -7.8319
-10.9521 -4.8834 -8.9684
t23 =
0
0.0001
0.0005
0.0025
0.0125
0.0625
0.1630
0.2946
0.4465
0.6123
0.7877
0.9253
1.0628
1.2088
1.3629
1.5231
1.6382
1.7534
1.8634
1.9948
2.1420
2.3030
2.4787
2.5880
2.6973
2.8149
2.9358
3.0112
3.0866
3.1779
3.2887
3.4194
3.5743
3.7559
3.9258
4.0873
4.2450
4.3499
4.4549
4.5441
4.6610
4.8035
4.9719
5.0000
y23 =
0 1.0000 3.0000
0.0001 1.0002 2.9999
0.0005 1.0014 2.9994
0.0025 1.0074 2.9967
0.0127 1.0373 2.9830
0.0683 1.1846 2.9068
0.2018 1.4677 2.7143
0.4175 1.8037 2.3787
0.7173 2.1276 1.8632
1.0927 2.3784 1.1327
1.5230 2.4947 0.1633
1.8651 2.4569 -0.7296
2.1931 2.2892 -1.7201
2.5049 1.9567 -2.8422
2.7680 1.4250 -4.0482
2.9391 0.6792 -5.2361
2.9808 0.0317 -5.9888
2.9432 -0.6952 -6.6090
2.8258 -1.4473 -7.0398
2.5736 -2.3932 -7.3018
2.1417 -3.4675 -7.2190
1.4913 -4.5901 -6.6375
0.5868 -5.6588 -5.4285
-0.0622 -6.1981 -4.4110
-0.7638 -6.6170 -3.2321
-1.5614 -6.9160 -1.8381
-2.4072 -7.0479 -0.3432
-2.9387 -7.0387 0.5848
-3.4669 -6.9604 1.4843
-4.0945 -6.7776 2.5055
-4.8279 -6.4375 3.5989
-5.6348 -5.8974 4.6105
-6.4892 -5.1199 5.3290
-7.3284 -4.1314 5.4155
-7.9536 -3.2589 4.7401
-8.4224 -2.5886 3.4724
-8.7936 -2.1722 1.7446
-9.0143 -2.0592 0.3888
-9.2309 -2.0949 -1.0833
-9.4239 -2.2499 -2.3950
-9.7071 -2.6321 -4.1468
-10.1317 -3.3750 -6.2602
-10.8003 -4.6297 -8.5953
-10.9338 -4.8762 -8.9580
嗯,感谢大侠的耐心解答,不过我还有个疑问是:dydt=[y(2);y(3);(cos(t)-5*y(2)-6*sin(t)*y(1))/3];中(cos(t)-5*y(2)-6*sin(t)*y(1))/3应该是等于y(3)吧,那么是不是dydt=[y(1);y(2);y(3)],然后这个是做什么用的?有点不太理解望高手支招,为了表达感谢,我已经将您的回答采纳为满意答案了·
ode23 ode45是对一阶微分方程的求解,高阶时要转为等号两边相差一阶的情况,如上所示,
令y(1)=y,dy(1)/dt=y(2)=y',dy(2)/dt=y(3)=y'',dy(3)/dt=y(4)=y''',调用函数分别写后三项等号右边的就可以了,其他类推,希望我说的明白,呵呵