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