Effacer les filtres
Effacer les filtres

Runge kutta 4th order method for Fitzhugh Nagumo model

4 vues (au cours des 30 derniers jours)
Vezzaz
Vezzaz le 4 Mar 2022
Commenté : Vezzaz le 4 Mar 2022
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

Réponse acceptée

Benjamin Thompson
Benjamin Thompson le 4 Mar 2022
Do you need to use x on the first line in the eq1 function that calls FN?
  1 commentaire
Vezzaz
Vezzaz le 4 Mar 2022
I used x because I thought that is what is needed for a differential equation. Also the differential equation is dv/dt and dw/dt so i used dx/dt as a substitute for v and dy/dt as a substitute for w. Which just made things more confusing. But now that I look at it that, x is probably where I went wrong and I am going to try and fix it.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by