Explicit Eulers Method for time advancement
์กฐํ ์: 5 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
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;
๋๊ธ ์: 1
๋ต๋ณ (1๊ฐ)
Alan Stevens
2021๋
2์ 22์ผ
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!
๋๊ธ ์: 0
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Programming์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!