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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!