# Explicit Eulers Method for time advancement

24 views (last 30 days)
Cassidy Holene on 22 Feb 2021
Answered: Alan Stevens on 22 Feb 2021
Hello I am trying to use explicit Euler for time advancement and the second-order centraldifference scheme for the spatial derivative, solve the equation to steady
state on a uniform grid. Plot the exact and numerical steady solutions for Nx = 10, 20.
๐๐/๐๐ก = ๐ผ*( ๐^2๐/๐๐ฅ^2) + ๐(๐ฅ) on the boundary of 0 โค ๐ฅ โค ๐ฟ๐ฅ The initial and boundary conditions are ๐(๐ฅ, 0) = 0 ๐(0,๐ก) = 0 ๐(๐ฟ๐ฅ,๐ก) = ๐steady(๐ฟ๐ฅ) Take ๐ผ = 1, ๐ฟ๐ฅ = 15, and ๐(๐ฅ) = โ(๐ฅ 2 โ 4๐ฅ + 2)๐ โ๐ฅ . The exact steady solution is ๐steady(๐ฅ) = ๐ฅ 2๐ โ๐ฅ
heres the code I have can someone explain where I went wrong
alpha =0;
x = 0;
n =10;
T(0)4ess = 0;
h=0.1;
s(x)=-(x^2-4*x+2)*exp^(-x);
for i=1:n
T(i+1)=T(i) + h;
T(i)^(n+1)=T(i+1)^n+((alpha*h)/(x+h)^2)*(T(i+1)^n-2T(i)^n+T(i-1)^n)+h*s(x);
x = x +1;
h = h +0.1;
end
plot(x,T);
grid on;
darova on 22 Feb 2021
Can you please write difference scheme in LaTeX?

Alan Stevens on 22 Feb 2021
T(i)^(n+1)
This will raise T(i) to the (n+1)th power!
You need another loop for time (say j = 1:something), then you can refer to T at position i and time j as
T(i,j)
On the right hand side
((alpha*h)/(x+h)^2)*(T(i+1)^n-2T(i)^n+T(i-1)^n)
should be
((alpha*h)/dx^2)*(T(i+1,j)-2T(i,j)+T(i-1,j))
where dx is the spatial interval (dx = Lx/n).
h is the timestep, so don't update it in the loop!