1D diffusion equation Backward Euler (No flux Boundary Conditions)

2 次查看(过去 30 天)
Hi, I am trying to solve a simple one dimensional diffusion equation, via Backward Euler Method:
dc/dt=D*d^2c/dx^2
Here is the code I created for the scheme using Neumann boundary conditions set to apply no flux at both boundaries, however this doesn't work and it produces something very bizarre. I'd greatly appreciate if someone can give me a hand.
N=4; % Size of matrix
%Main Matrix
A=diag((1+2*lambda)*ones(N,1))+diag(-lambda*ones(N-1,1),1)+diag(-lambda*ones(N-1,1),-1);
A(1,2)=-2*lambda;
A(N,N-1)=-2*lambda;
u=ones(N,1)*0.5; % Initial Condition
% With output:
A =
[ 2*lambda + 1, -2*lambda, 0, 0]
[ -lambda, 2*lambda + 1, -lambda, 0]
[ 0, -lambda, 2*lambda + 1, -lambda]
[ 0, 0, -2*lambda, 2*lambda + 1]
but when I try to solve via
for i=1:Time
new=A\b
U(:,i)=new;
b=new;
end
it returns nonsense. Please help !
Thank you

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by