Why is ode45 not working when I insert the options input?

조회 수: 1 (최근 30일)
Rina Dirickson
Rina Dirickson 2022년 6월 29일
댓글: Jon 2022년 6월 30일
I am trying to model some functions, but it seems that ode45 is not working. However, when I get rid of 'options' when I'm calling ode45, it runs but it will not finish running. I'm still new to MATLAB, so how can I fix this issue?
%CONSTANTS
i = 6.3;
a = 1;
b = 0.83;
vNa = 115;
vK = -12;
vL = 10.5989;
simtime = [0 100];
xinit = [0, 0.4, 0.1];
%CALLING FUNCTIONS
options=odeset('RelTol',1e-9,'Refine',10);
[t,x]=ode45(@(t,x) HHModel(t,i,a,b,vNa,vK,vL,x),simtime,xinit, options);
%GRAPHS
%Membrane Potential
subplot(221); plot(t,x(:,1)); grid on;
xlabel('Time [s]'); ylabel('v');
%FUNCTIONS
function amv = am(v)
amv = ((25-v)/10)/((exp((25-v)/10))-1);
end
function bmv = bm(v)
bmv = 4*exp(-v/18);
end
function tmv = tm(v)
tmv = 1/(am(v) + bm(v));
end
function anv = an(v)
anv = ((10-v)/100)/((exp((10-v)/10))-1);
end
function bnv = bn(v)
bnv = 0.125*exp(-v/80);
end
function dx = HHModel(t,i,a,b,vNa,vK,vL,x)
amv = am(x(1));
tmv = tm(x(1));
anv = an(x(1));
bnv = bn(x(1));
dx1 = i - 120*(x(3))^3*(b - a*(x(2)))*(x(1)-vNa) - 36*(x(2))^4*(x(1)-vK)-0.3*(x(1)-vL);
dx2 = anv - x(2)*(anv - bnv);
dx3 = amv - (x(3)/tmv);
dx = [dx1;dx2;dx3];
end

채택된 답변

Jon
Jon 2022년 6월 29일
Try ode15s instead, it seems to converge, you have to check if the answer makes sense
%CALLING FUNCTIONS
options=odeset('RelTol',1e-9,'Refine',10);
[t,x]=ode15s(@(t,x) HHModel(t,i,a,b,vNa,vK,vL,x),simtime,xinit,options);
  댓글 수: 3
Rina Dirickson
Rina Dirickson 2022년 6월 29일
Thank you so much!
Jon
Jon 2022년 6월 30일
Your welcome, glad this helped.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by