Problem with input of ode113

6 ビュー (過去 30 日間)
Maarten Duijn
Maarten Duijn 2019 年 12 月 2 日
コメント済み: Maarten Duijn 2019 年 12 月 2 日
I'm trying to run a very simple ODE. However when running it Matlab shows me the error: 'Index in position 1 exceeds array bounds (must not exceed 1)' for I_2 in the QIF function.
My code is posted below:
I_1= pi^2;
I_2= -2*pi^2;
params.tau= 10;
g= 0;
V_1= -65;
V_2= -65;
state= [V_1;V_2];
I= [I_1;I_2];
options = odeset('abstol',1e-8,'reltol',1e-8);
[t,state] = ode113(@QIF,[1 3000],state,I,params)
With QIF :
function [statep]= QIF(t,state,I,params);
I_1= I(1);
I_2=I(2);
v= (state(1)+state(2))/length(state);
V_1d= ((state(1)^2)+ I_1)/params.tau;
V_2d= ((state(2)^2)+ I_2)/params.tau;
statep= [V_1d,V_2d]
Does anyone see what I don't see?

採用された回答

Stephan
Stephan 2019 年 12 月 2 日
I_1= pi^2;
I_2= -2*pi^2;
params.tau= 10;
g= 0;
V_1= -65;
V_2= -65;
state= [V_1;V_2];
I= [I_1;I_2];
options = odeset('abstol',1e-8,'reltol',1e-8);
[t,state] = ode113(@(t,state)QIF(t,state,I,params),[1 10.8],state,options);
plot(t,state)
function statep= QIF(~,state,I,params)
I_1= I(1);
I_2=I(2);
V_1d= ((state(1)^2)+ I_1)/params.tau;
V_2d= ((state(2)^2)+ I_2)/params.tau;
statep = [V_1d;V_2d];
end
For t>10.84627 your function gives a warning due to the extreme rise of the resulting values. Maybe you should check if your implementation is correct.
  3 件のコメント
Stephan
Stephan 2019 年 12 月 2 日
Sounds like you might want to use ode events to tackle this. In the given link there is an example of a jumping ball - i suspect this is the kind of thing you want to do.
Maarten Duijn
Maarten Duijn 2019 年 12 月 2 日
Yes, thats kind of what I want to use. I used the event function of the ballode function and the event outputs. However, the event function does not recognize the value at which it needs to terminate the ode solver.
function [value,isterminal,direction] = QIF_reset(t,y)
% Locate the time when height passes through zero in a decreasing direction
% and stop integration.
value =100-y(1); % detect height = 0
isterminal = 1; % stop the integration
direction = -1; % negative direction
The ode will keep solving past the event of y(1) reaching 100.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by