Why are values in my loop filled with NaN?
Show older comments
Hello,
Can anyone tell why 'u' and 'v' inside my loop are all being filled with NaN? I cant figure out what I'm doing wrong. Thanks!
close all;
clear all;
a = 0;
b = 20;
nel = 200; % number of elements
h = (b-a)/nel; % step size
nv = nel+1;% number of vertices
x = a:h:b; % mesh
dt = 0.001; % time steps
tend = 20;
e=ones(nv, 1);
%Discretization of the Laplace operator
Delta=1/(h^2)*spdiags([e -2*e e], -1:1, nv, nv);
Delta(1,2) = 2/h^2;
Delta(end,end-1) = -2/h^2;
% parameters of the model
eps = 0.02;
alpha = 0.1;
% initial guess
u = 0.5 * (x < 3);
v = 0 * x;
counter = 1;
% explicit Euler scheme
for t=dt:dt:tend
u = u + dt/eps*(u .*(1-u).*(u-alpha) - v - ((Delta * u')'));
v = v + dt * (u - v);
end
figcure(1)
plot(x,u,x,v,'r');
legend('u','v')
title('Solution of the Fitz-Hugh-Nagumo system')
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!