Problem using ode23tb (Error: Index exceeds the number of array elements)

1 次查看(过去 30 天)
Hello
I am trying to use the function ode23tb to solve the system of ODEs described bellow. However, I am having trouble, because the function returns an error, namely "Index exceeds the number of array elements (1)". I am not sure which variable is causing the problem. I am indexing the argument y within f, but, as far as I can understand, the same thing is done in the vdp1000 example in the ode23tb documentation and it causes no trouble. Thanks in advance for your help.
VDD = 10;
Ld = 120e-6;
Cg = 50e-12;
Cb = 40e-12;
RS = 50;
RL = 6.6;
iD = @(vG,vD) 10*(1/2.*(vG-3)+1/20.*log(2*cosh(10*(vG-3)))).*(1+0.003.*vD).*tanh(vD);
f = @(y,vs)[
1/Cg*((vs-y(1))/RS-iD(y(1),y(2))-y(3)-y(2)/RL);
1/Cg*(vs-y(1))/RS-(Cb+Cg)/(Cb*Cg)*(iD(y(1),y(2))+y(3)+y(2)/RL);
(y(2)-VDD)/Ld;
];
ff = @(y,t) f(y,3+20*sin(2*pi*10e6*t));
[t,y] = ode23tb(ff,[0 pi/(10e6*pi)],[3; 10; 10/6.6]);

采纳的回答

Alan Stevens
Alan Stevens 2021-1-18
编辑:Alan Stevens 2021-1-18
Must be something to do with the nested functions! It works when structured as follows:
[t,y] = ode23tb(@yfn,[0 pi/(10e6*pi)],[3; 10; 10/6.6]);
plot(t,y),grid
function dydt = yfn(t,y)
VDD = 10;
Ld = 120e-6;
Cg = 50e-12;
Cb = 40e-12;
RS = 50;
RL = 6.6;
vG = y(1); vD = y(2);
iD = 10*(1/2.*(vG-3)+1/20.*log(2*cosh(10*(vG-3)))).*(1+0.003.*vD).*tanh(vD);
vs = 3+20*sin(2*pi*10e6*t);
dydt = [1/Cg*((vs-y(1))/RS-iD-y(3)-y(2)/RL);
1/Cg*(vs-y(1))/RS-(Cb+Cg)/(Cb*Cg)*(iD+y(3)+y(2)/RL);
(y(2)-VDD)/Ld];
end
(Not clear why you have pi/(constant*pi) as the pi's will cancel each other).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by