Need some help, Four coupled ODEs with ode45
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert
am 19 Nov. 2014
Kommentiert: Star Strider
am 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 Kommentare
Andrew Reibold
am 19 Nov. 2014
Saying you have consulted every manual and example online is quite a bold statement, lol.
Akzeptierte Antwort
Star Strider
am 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
- Combine ‘x’ and ‘y’ into one ‘xy’ variable so ode45 would like it;
- Add ‘fntest’ to the ode45 function call argument list, since ode45 likes to be told what function you want it to integrate;
- Took the function call outside of the ‘fntest’ function, since that creates recursion problems;
- Added the fourth initial condition to the vector in your ode45 argument list to match the number of first-order ODEs in your function.
- 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 Kommentare
Star Strider
am 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')
Weitere Antworten (1)
Torsten
am 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!