why is my function not working?
显示 更早的评论
function CMO=ppl (t,y)
a0=30;a1=14;a2=50;a3=20;b3=a3;g=1;
dy1=y(2);
dy2=y(3);
dy3=b3/a0*g-a1/a0*y(3)-a2/a0*y(2)-a3/a0*y(1);
CMO=[dy1;dy2;dy3];
[t,y]=ode23 ('ppl',[0,5],[0,0,0]);% in command window
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
2 个评论
The function works fine for me. Here's the output.
t =
0
0.00012
0.00072
0.00372
0.01872
0.0521
0.085669
0.11946
0.15349
0.18781
0.22242
0.25944
0.30302
0.35456
0.41588
0.48947
0.57896
0.69019
0.83431
1.0111
1.2065
1.4231
1.6663
1.8763
2.0559
2.1671
2.2784
2.4143
2.5807
2.7772
3.0085
3.2516
3.466
3.6104
3.7548
3.8762
4.0363
4.2349
4.4512
4.6403
4.7521
4.8638
5
y =
0 0 0
1.92e-13 4.7999e-09 7.9998e-05
4.147e-11 1.7278e-07 0.00047992
5.7184e-09 4.6101e-06 0.0024778
7.2797e-07 0.00011647 0.012424
1.5633e-05 0.00089722 0.034288
6.9163e-05 0.0024117 0.055871
0.00018664 0.0046604 0.077149
0.00039404 0.0076442 0.098095
0.00071816 0.011365 0.11868
0.0011868 0.015825 0.13888
0.0018725 0.021354 0.15979
0.0029627 0.028839 0.18347
0.0047049 0.038987 0.21006
0.0075098 0.052786 0.23958
0.012074 0.071624 0.27177
0.01962 0.097512 0.30583
0.032439 0.13352 0.33992
0.055342 0.18486 0.36971
0.093934 0.2518 0.38333
0.15045 0.32579 0.3691
0.22945 0.40097 0.31954
0.33567 0.46812 0.22767
0.43831 0.5054 0.1251
0.53059 0.51909 0.026645
0.58837 0.51853 -0.036722
0.64569 0.5109 -0.1003
0.71397 0.49205 -0.17632
0.79299 0.45531 -0.26359
0.87674 0.39436 -0.35326
0.95765 0.30276 -0.4329
1.0178 0.19094 -0.4794
1.0476 0.08692 -0.48537
1.0551 0.017718 -0.47062
1.0528 -0.048289 -0.4413
1.0438 -0.099847 -0.40612
1.0228 -0.16026 -0.34662
0.98468 -0.22029 -0.25569
0.93188 -0.26341 -0.14163
0.88015 -0.28017 -0.035751
0.84875 -0.28065 0.026896
0.81769 -0.27421 0.088081
0.78139 -0.25731 0.15893
madhan ravi
2018-12-4
And the interesting thing is you used ode23 and your error message shows error in ode45 something is fishy here..
回答(1 个)
madhan ravi
2018-12-4
1 个投票
change 'ppl' to @ppl
3 个评论
madhan ravi
2018-12-4
编辑:madhan ravi
2018-12-4
well interesting this is what I got: (version 2018b) if you see https://www.mathworks.com/help/matlab/ref/ode23.html#bu78c6p the last line in input argument says that Data Types should be a function_handle meaning that they have changed it in recent versions (to be noted it's 2018b documentation)
Error using feval
Undefined function or variable 'ppl'.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options,
varargin);
Error in COMMUNITY (line 1)
[t,y]=ode23 ('ppl',[0,5],[0,0,0]);% in com
>>
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!