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

2 views (last 30 days)
Rina Dirickson
Rina Dirickson on 29 Jun 2022
Commented: Jon on 30 Jun 2022
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

Accepted Answer

Jon
Jon on 29 Jun 2022
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 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!