Need some help, Four coupled ODEs with ode45

1 vue (au cours des 30 derniers jours)
Robert
Robert le 19 Nov 2014
Commenté : Star Strider le 20 Nov 2014
Hi there, I'm fairly new to MATLAB, and I have never used the ODE integrators before. I'm trying to plot the solution to a two-cell coupled Fitzhugh-Nagumo model.
The equations must be coupled through the y variable, as I have written in lines 7 and 10. I have tried several different methods of writing the functions, but every time I end up with the "not enough input arguments" error.
Please help, I've consulted every manual and example online but cannot seem to figure out what I'm doing wrong. The file is attached.
Thank you in advance!
  2 commentaires
Andrew Reibold
Andrew Reibold le 19 Nov 2014
Saying you have consulted every manual and example online is quite a bold statement, lol.
Robert
Robert le 20 Nov 2014
Lol. I was in a tizzy. That's an exaggeration... obviously.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 19 Nov 2014
Your version of the Fitzhugh-Nagamo model isn’t one I’m used to seeing, so I can’t comment on you implementation of it.
This code works:
This belongs in its own function file:
function dydt = fntest(t,xy)
dydt = zeros(size(xy));
x = xy(1:2);
y = xy(3:4);
for I = [0.2:0.05:1.0];
% Evaluate the expression
dydt(1) = x(1) - x(1).^3/3 - x(2) + y(1)*I;
dydt(2) = 0.07*(x(1) + 0.7 - 0.8*x(2));
dydt(3) = x(1) - x(1).^3/3 - x(2) + -y(1)*I;
dydt(4) = 0.07*(x(1) + 0.7 - 0.8*x(2));
end
end
Then in your main script file:
[t,xy] = ode45(@fntest,[0 4],[0 0 0 0]);
figure
plot(t,xy);
The corrections I made were to
  1. Combine ‘x’ and ‘y’ into one ‘xy’ variable so ode45 would like it;
  2. Add ‘fntest’ to the ode45 function call argument list, since ode45 likes to be told what function you want it to integrate;
  3. Took the function call outside of the ‘fntest’ function, since that creates recursion problems;
  4. Added the fourth initial condition to the vector in your ode45 argument list to match the number of first-order ODEs in your function.
  5. I added an end to it because I run functions for MATLAB Answers as nested functions inside a test function, but it is not strictly required if you make it a separate function file.
Put ‘fntest’ in its own function file named ‘fntest.m’ and then run the ode45 call to it and the plot from your main script.
  4 commentaires
Robert
Robert le 20 Nov 2014
Crap. One more question. You commented on my implementation of the Fitzhugh-Nagumo model... I was pretty sure that this was the correct way to write out the same model to which you linked, but apparently it is not (judging by the output). Would you mind showing me how to output it correctly? I sincerely appreciate your effort.
Star Strider
Star Strider le 20 Nov 2014
My pleasure!
This is one I retrieved from my archives:
ode = @(t,vw) [vw(1) - (vw(1).^3)/3 - vw(2) + 1; (vw(1) + 0.1 - 0.2.*vw(2))/1.5];
tspan = [0, 40];
y0 = [1; 1];
[t,vw] = ode45(ode, tspan, y0);
figure(1)
plot(t,vw(:,1),'r')
hold on
plot(t,vw(:,2),'b')
hold off
legend('V','W','Location','NE')
xlabel ('t')
ylabel('Amplitude')
title ('FitzHugh-Nagamo Giant Squid Axon Model')

Connectez-vous pour commenter.

Plus de réponses (1)

Torsten
Torsten le 20 Nov 2014
Use the for-Loop in the call to ode45, not in fntest:
For k=1:5
II=0.05*k;
[t,xy] = ode45(@(t,y)fntest(t,y,II),[0 4],[0 0 0 0]);
plot(t,xy);
end
Best wishes
Torsten.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by