MATLAB: Need some help, Four coupled ODEs with ode45

MATLABnonlinear odeode45system of equations

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!

Best Answer

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.