1D diffusion equation Backward Euler (No flux Boundary Conditions)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!