Runge kutta 4th order method for Fitzhugh Nagumo model
6 ビュー (過去 30 日間)
古いコメントを表示
So I wrote a runge kutta 4th order code, or what I believe to be one, to solve the fitzhugh-nagumo model equations I was given to solve. I am getting a left side is a 1x1 and the right side is a 2x2 at line 42. I may have done the runge kutta wrong, but I tried changing some things around to make it a 1x1 to a 1x1 but that gave even more errors. Any help would be greatly appreciated, thank you.
clear all
close all
eq1=@(t,x) FN(t,2,0.1,0.1,-0.1);
[x, t] = rk4(eq1,0);
v=x(:,1);
w=x(:,2);
figure(1)
plot(v)
hold on
plot(w)
function dvwdt = FN(~,a,L,e,I) %
x(1)=0; %initial condition for v
x(2)=0; %initial condition for w
v=x(1);
w=x(2);
dvwdt = [I-2*v^2+3*v^2-w; %dv/dt
e*(a*v-L-w)]; %dw/dt
end
function [x, t] = rk4(f, x0)
t0=0; %starting time
dt=0.01; %step size
tf=100; %ending time
t=t0:dt:tf;
nt=numel(t);
nx=numel(x0);
x=nan(nx,nt);
x(:,1)=x0;
for k=1:nt-1
k1= dt*f(t(k),x(:,k));
k2= dt*f(t(k)+dt/2,x(:,k)+k1/2);
k3= dt*f(t(k)+dt/2,x(:,k)+k2/2);
k4= dt*f(t(k)+dt,x(:,k)+k3);
dx=(k1+2*k2+2*k3+k4)/6;
x(:,k+1)= x(:,k)+dx;
end
end
0 件のコメント
採用された回答
Benjamin Thompson
2022 年 3 月 4 日
Do you need to use x on the first line in the eq1 function that calls FN?
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!