function dfdt=myfun(t,x)
dfdt = [...
x(2);
(1.5*((x(2))^2)*(cos(3*(x(1)))))-(((pi/2)^2) * ...
(sin((pi*t)/2)))-(20*((x(1))-(sin((pi*t)/2)))) - ...
((0.5*((x(2))^2)*abs(cos(3*(x(1)))))+0.1) * ...
sat(((x(2)-((pi/2)*cos((pi*t)/2))) + ...
(20*(x(1)-(sin((pi*t)/2)))))/0.1)-(((abs(sin(t)))+1) * ...
(cos(3*x(1)))*((x(2))^2))
];
该等式中的 sat
定义如下:
function f = sat(y)
if abs(y) <= 1
f = y;
else
f = sign(y);
end
我首先使用ODE45作为ODE解决它,我将微分方程定义为向量:
[t, x] = ode45(@myfun, [0 4], [0 pi/2])
这很好用。但是当我尝试使用fde12
来解决相同的方程组时:
[T,Y] = FDE12(ALPHA,FDEFUN,T0,TFINAL,Y0,h)
现在我称之为:
t0 = 0;
tfinal= 4 ;
h = 0.01;
x0 = [0 pi/2];
[t, x] = fde12(0.95, @myfun, t0,tfinal, x0,h);
(alpha
是分数微分的顺序,例如0.95
)
它出现以下错误:
Attempted to access x(2); index out of bounds because numel(x) = 1.
答案 0 :(得分:1)
RTFM - 或者在这种情况下:the description:
初始条件集Y0是一个矩阵,其行数等于问题的大小
然而,你指定
x0 = [0 pi/2];
这有两列。如果将其更改为两行:
x0 = [0; pi/2];
它会起作用。 (我刚试过你的例子)。