Need some help, Four coupled ODEs with ode45
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Andrew Reibold
2014 年 11 月 19 日
Saying you have consulted every manual and example online is quite a bold statement, lol.
採用された回答
Star Strider
2014 年 11 月 19 日
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 件のコメント
Star Strider
2014 年 11 月 20 日
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')
その他の回答 (1 件)
Torsten
2014 年 11 月 20 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!