1. MATLAB CODE FOR FISHER’S EQUATION
clear all
clc
%=====================================================
%ut=uxx+u(1-u) x->[a,b] , t>0
%u(a,t)=u(b,t)=0
%u(x,0)=g(x)
%=====================================================
%----------------------INTIALIZATION----------------------
a=-50; %lower bound on x
b=50; %upper bound on x
N=175; % number of inner points
hx =(2*b)/(N-1); %stepsize in x direction
ht=.21; %stepsize in t
t0=0; %starting time
tend=55; %ending time
dim=ceil(tend/ht);
t=linspace(t0, tend, dim);
xj=linspace(a, b, N); %discretizing X-grid //
T=linspace(t0,tend, N) --> %discretizing T-grid
%-------------------------MATRIX A-------------------------
% CREATING MATRIX A FOR INNER PTS
A=zeros(N,N);
for i=1:N-2
A(i+1,i)=1;
A(i+1,i+1)=-2;
A(i+1,i+2)=1;
end
% CREATE VECTOR FOR UPPER BOUND BC
BCN=zeros(1,N-3);
BCN=[BCN 0];
BCN=[BCN 2];
BCN=[BCN -2];
% ADD BC VECTORS TO ORGINAL MATRIX A (upper bound)
A(end,:) = BCN;
% ADD BC VECTORS TO ORGINAL MATRIX A (lower bound)
A(1,1)=-2;
A(1,2)= 2;
A(1,3)= 0;
%---------------------INTIAL CONDTION----------------------
% INITAL CONDTION 1
g1=zeros (1,N);
2. i=0;
for x= a:hx:b
i=i+1;
if abs(x)<=15
g1(i)=.99;
end
end
% INITAL CONDTION 2
g2=zeros (1,N);
i=0;
for x= a:hx:b
i=i+1;
X(i)=x;
if abs(x)<=5
s=.25*(cos((pi*x)/10))^2;
g2(i)=s;
end
end
%----------------------ITERATIONS-------------------------
%------------------------RK 4-----------------------------
i=1;
u0=g2;
C= zeros(N,dim);
C(:,i)=g2;
for t=t0:ht:tend
k1= u0*A*(1/hx^2)+u0.*(1 - u0);
k2= (u0+(ht/2).*k1)*A*(1/hx^2)+(u0+(ht/2).*k1).*(1 -
(u0+(ht/2).*k1));
k3= (u0+(ht/2).*k2)*A*(1/hx^2)+(u0+(ht/2).*k2).*(1 -
(u0+(ht/2).*k2));
k4= (u0+ht.*k3)*A*(1/hx^2)+(u0+ht.*k3).*(1 - (u0+ht.*k3));
u1 = u0+(ht/6)*(k1 + 2*k2 + 2*k3 + k4);
u0=u1;
i=i+1;
C(:,i)=u1;
end
aviobj = avifile('FishersEquation.avi','compression','None');
%---------------------PLOT SOLUTION-----------------------
s=numel(C(:,1));
i=1;