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

2 Ansichten (letzte 30 Tage)
Elias Siguenza
Elias Siguenza am 9 Jan. 2015
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

Antworten (0)

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by