SlideShare a Scribd company logo
1 of 3
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);
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;
scatter(xj, C(:,1))
for k=0:dim
scatter(xj,C(:,i));
M(i)= getframe;
i=i+1;
aviobj = addframe(aviobj,gcf);
drawnow
end
xlabel('x')
ylabel('u(x,t)')
title ('Solution to Fishers Equation Using RK-4 Scheme')
viobj = close(aviobj)

More Related Content

What's hot

All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraEric Normand
 
Ramco C Question Paper 2003
Ramco  C  Question  Paper 2003Ramco  C  Question  Paper 2003
Ramco C Question Paper 2003ncct
 
Bayesian workflow with PyMC3 and ArviZ
Bayesian workflow with PyMC3 and ArviZBayesian workflow with PyMC3 and ArviZ
Bayesian workflow with PyMC3 and ArviZCorrie Bartelheimer
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programsAnanda Kumar HN
 
TypeLevel Summit
TypeLevel SummitTypeLevel Summit
TypeLevel SummitLuca Belli
 
ML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional LanguageML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional Languagelijx127
 
Fichas de trabalho 3º ano
Fichas de trabalho   3º anoFichas de trabalho   3º ano
Fichas de trabalho 3º anoclaudiaalves71
 
型理論 なんて自分には関係ないと思っているあなたへ
型理論 なんて自分には関係ないと思っているあなたへ型理論 なんて自分には関係ないと思っているあなたへ
型理論 なんて自分には関係ないと思っているあなたへYusuke Matsushita
 
Linear regression using least squares
Linear regression using least squaresLinear regression using least squares
Linear regression using least squaresWaleed Zaghal
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th StudyChris Ohk
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)GroovyPuzzlers
 
A Beginners Guide to Weather & Climate Data, Margriet Groenendijk
A Beginners Guide to Weather & Climate Data, Margriet GroenendijkA Beginners Guide to Weather & Climate Data, Margriet Groenendijk
A Beginners Guide to Weather & Climate Data, Margriet GroenendijkPôle Systematic Paris-Region
 

What's hot (15)

Polar plots with R
Polar plots with RPolar plots with R
Polar plots with R
 
All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School Algebra
 
Ramco C Question Paper 2003
Ramco  C  Question  Paper 2003Ramco  C  Question  Paper 2003
Ramco C Question Paper 2003
 
Bayesian workflow with PyMC3 and ArviZ
Bayesian workflow with PyMC3 and ArviZBayesian workflow with PyMC3 and ArviZ
Bayesian workflow with PyMC3 and ArviZ
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
TypeLevel Summit
TypeLevel SummitTypeLevel Summit
TypeLevel Summit
 
ML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional LanguageML: A Strongly Typed Functional Language
ML: A Strongly Typed Functional Language
 
Fichas de trabalho 3º ano
Fichas de trabalho   3º anoFichas de trabalho   3º ano
Fichas de trabalho 3º ano
 
Graph Algebra
Graph AlgebraGraph Algebra
Graph Algebra
 
型理論 なんて自分には関係ないと思っているあなたへ
型理論 なんて自分には関係ないと思っているあなたへ型理論 なんて自分には関係ないと思っているあなたへ
型理論 なんて自分には関係ないと思っているあなたへ
 
Linear regression using least squares
Linear regression using least squaresLinear regression using least squares
Linear regression using least squares
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
 
A Beginners Guide to Weather & Climate Data, Margriet Groenendijk
A Beginners Guide to Weather & Climate Data, Margriet GroenendijkA Beginners Guide to Weather & Climate Data, Margriet Groenendijk
A Beginners Guide to Weather & Climate Data, Margriet Groenendijk
 
Bisection methode alternate
Bisection methode alternateBisection methode alternate
Bisection methode alternate
 

Viewers also liked

Financialmodeling
FinancialmodelingFinancialmodeling
FinancialmodelingTalal Tahir
 
Anil Menariya Awards
Anil Menariya AwardsAnil Menariya Awards
Anil Menariya AwardsAnil Menariya
 
Clay pots full of treasure lectio divina
Clay pots full of treasure   lectio divinaClay pots full of treasure   lectio divina
Clay pots full of treasure lectio divinaBill Faris
 
Sendo ágil de verdade - qualidade e mudanças de mãos dadas!
Sendo ágil de verdade - qualidade e mudanças de mãos dadas!Sendo ágil de verdade - qualidade e mudanças de mãos dadas!
Sendo ágil de verdade - qualidade e mudanças de mãos dadas!Luís Cobucci
 
Research & Customer Development
Research & Customer DevelopmentResearch & Customer Development
Research & Customer DevelopmentTudor Ice Company
 
Profesor paquini
Profesor paquiniProfesor paquini
Profesor paquiniplantel611
 
Propiedad intelectual
Propiedad intelectualPropiedad intelectual
Propiedad intelectualluislimache25
 

Viewers also liked (14)

Financialmodeling
FinancialmodelingFinancialmodeling
Financialmodeling
 
Anil Menariya Awards
Anil Menariya AwardsAnil Menariya Awards
Anil Menariya Awards
 
Clay pots full of treasure lectio divina
Clay pots full of treasure   lectio divinaClay pots full of treasure   lectio divina
Clay pots full of treasure lectio divina
 
English 3 lm
English 3 lmEnglish 3 lm
English 3 lm
 
Lucy
LucyLucy
Lucy
 
Sendo ágil de verdade - qualidade e mudanças de mãos dadas!
Sendo ágil de verdade - qualidade e mudanças de mãos dadas!Sendo ágil de verdade - qualidade e mudanças de mãos dadas!
Sendo ágil de verdade - qualidade e mudanças de mãos dadas!
 
Research & Customer Development
Research & Customer DevelopmentResearch & Customer Development
Research & Customer Development
 
SWMS
SWMSSWMS
SWMS
 
Marisol
MarisolMarisol
Marisol
 
Revenue Models
Revenue ModelsRevenue Models
Revenue Models
 
Profesor paquini
Profesor paquiniProfesor paquini
Profesor paquini
 
WeSketch MVP
WeSketch MVPWeSketch MVP
WeSketch MVP
 
Propiedad intelectual
Propiedad intelectualPropiedad intelectual
Propiedad intelectual
 
the speaking process
the speaking processthe speaking process
the speaking process
 

Similar to FishersEquationCode

Implicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcsImplicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcsParhamsagharchi
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Dr. Volkan OBAN
 
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...Parhamsagharchi
 
matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmGyana Ranjan Mati
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 

Similar to FishersEquationCode (6)

Implicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcsImplicit crank nicolson - du fort-frankel - ftcs
Implicit crank nicolson - du fort-frankel - ftcs
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
 
matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdm
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Numerical Methods Solving Linear Equations
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 

FishersEquationCode

  • 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;
  • 3. scatter(xj, C(:,1)) for k=0:dim scatter(xj,C(:,i)); M(i)= getframe; i=i+1; aviobj = addframe(aviobj,gcf); drawnow end xlabel('x') ylabel('u(x,t)') title ('Solution to Fishers Equation Using RK-4 Scheme') viobj = close(aviobj)