implicit-explicit method for finite difference method under reaction diffusion equataions
14 views (last 30 days)
Show older comments
Hello, I am trying to solve the following reaction diffusion numerically under implicit-explicit method.
I try to compare my numerical solution to artifical true solution by define
The implicit -explicit scheme is straight forward and I will skip the derivation. However, the error between numerical and analytic solution does not follow the first order as dx goes to 0. I am wondering where I made a small but stupid mistake. Codes are attached. Thanks for any comment.
L = 50; % spatial size
Time = 50; % final time
delta = 0.05;
index=0:1:5;
h=power(3,-index);
forward_true=@(time,space) (cos(pi.*space/50).^2-1/2).*exp(0.01*time);
f_true=@(dk) (0.01+4*(pi/50).^2+delta)*dk;
error=zeros(1,length(index));
for test=1:length(index)
dx=h(test);
dt=dx;
x=0:dx:L;
t=0:dt:Time;
A=1;
N=length(t);
M=length(x);
mu = dt/dx/dx;
[X,T] = meshgrid(x,t); % This will create two matrices, T and X, where each element of t and x is paired with the other.
data=forward_true(T,X);
K0=cos(pi.*x/50).^2-1/2;
solu=zeros(N,M);
solu(1,:)=K0;
% implicit method
main_diag=1+2*mu+delta*dt;
upper=-mu;
lower=-mu;
Mdiag=main_diag*ones(M,1);
Muppder=upper*ones(M-1,1);
Mlower=lower*ones(M-1,1);
matrix=diag(Mdiag)+diag(Muppder,1)+diag(Mlower,-1);
matrix(1,2)=-2*mu;
matrix(end,end-1)=-2*mu;
for tstep=1:N-1
Kc = solu(tstep,:)';
Knext=zeros(1,M);
fvalue = f_true(Kc);
RHS=Kc+dt*fvalue;
Knext=matrix\RHS;
solu(tstep+1, :) = Knext;
end
error(test)=norm(data-solu,inf);
disp(test)
end
Answers (0)
See Also
Categories
Find more on Boundary Conditions 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!