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

2 vues (au cours des 30 derniers jours)
Elias Siguenza
Elias Siguenza le 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

Réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by