A question about FitzHugh-Nagumo model

12 次查看(过去 30 天)
I`ve been trying to built the FitzHugh-Nagumo model with a changeable input,but I failed to make the input changeable and I was unable to figure out why.
I defined three variables which I thought they should be the same,but only the variable 'eq1' and the way I put in the comment worked out,the others ended without graph out.I wonder how could this happened and how should I change the code of 'eq2' and 'eq3' .
syms t
tspan = [0 100];
v0 = 0; w0 = 0;
IC = [v0 w0];
A=0.5;
B=0.05;
Epsilon=0.005;
I=sin(t);
eq1=@(t,vw)fn(t,vw,A,B,Epsilon,sin(t));
eq2=@(t,vw)fn(t,vw,A,B,Epsilon,0)+[sin(t);0];
eq3=@(t,vw)fn(t,vw,A,B,Epsilon,I);
[t, vw] = ode45(eq1, tspan,IC);
%[t, vw] = ode45(@(t,vw)fn(t,vw,A,B,Epsilon,sin(t)), tspan,IC);
v = vw(:,1);
w = vw(:,2);
% results
plot(t,v,'r',t,w,'b'),grid
xlabel('t'),ylabel('v and w')
legend('v','w')
function dvwdt = fn(~,vw,A,B,Epsilon,I)
a = A;
b = B;
epsilon = Epsilon;
i = I;
v = vw(1);
w = vw(2);
dvwdt = [(v*(v-a)*(1-v)-w+i)/epsilon;
v-w-b];
end

采纳的回答

Alan Stevens
Alan Stevens 2021-11-9
Like this?
tspan = [0 100];
v0 = 0; w0 = 0;
IC = [v0 w0];
A=0.5;
B=0.05;
Epsilon=0.005;
I=@(t)sin(t); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eq1=@(t,vw)fn(t,vw,A,B,Epsilon,sin(t));
eq2=@(t,vw)fn(t,vw,A,B,Epsilon,0)+[sin(t);0];
eq3=@(t,vw)fn(t,vw,A,B,Epsilon,I(t));
[t1, vw1] = ode45(eq1, tspan,IC);
[t2, vw2] = ode45(eq2, tspan,IC);
[t3, vw3] = ode45(eq3, tspan,IC);
v1 = vw1(:,1); v2 = vw2(:,1); v3 = vw3(:,1);
w1 = vw1(:,2); w2 = vw2(:,2); w3 = vw3(:,2);
% results
figure
plot(t1,v1,'r',t1,w1,'b'),grid
xlabel('t1'),ylabel('v1 and w1')
legend('v1','w1')
figure
plot(t2,v2,'r',t2,w2,'b'),grid
xlabel('t2'),ylabel('v2 and w2')
legend('v2','w2')
figure
plot(t3,v3,'r',t3,w3,'b'),grid
xlabel('t3'),ylabel('v3 and w3')
legend('v3','w3')
function dvwdt = fn(~,vw,A,B,Epsilon,I)
a = A;
b = B;
epsilon = Epsilon;
i = I;
v = vw(1);
w = vw(2);
dvwdt = [(v*(v-a)*(1-v)-w+i)/epsilon;
v-w-b];
end
  3 个评论
Alan Stevens
Alan Stevens 2021-11-12
In eq2, the value of I passed to fn is zero. To see the effect this has change eq2 so that it doesn't add the [sin(t); 0] term. You will then see that this last vector just produces oscillations about two very different values.
shuhao hu
shuhao hu 2021-11-15
Thank you very much!I got it,you must be Jesus!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by