MATLAB Answers

Explicit Eulers Method for time advancement

24 views (last 30 days)
Cassidy Holene
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;
for i=1:n
T(i+1)=T(i) + h;
x = x +1;
h = h +0.1;
grid on;
  1 Comment
darova on 22 Feb 2021
Can you please write difference scheme in LaTeX?

Sign in to comment.

Answers (1)

Alan Stevens
Alan Stevens on 22 Feb 2021
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
On the right hand side
should be
where dx is the spatial interval (dx = Lx/n).
h is the timestep, so don't update it in the loop!

Community Treasure Hunt

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

Start Hunting!