Hi Xavier,
To change from the explicit method to the implicit method for calculating temperature distribution across a slab, here’s a high-level explanation of the steps needed to implement the implicit finite difference method:
- Define Parameters and Set Initial Conditions: Set up the slab length, time steps, and boundary conditions, same as in the explicit method.
- Construct the Coefficient Matrix (A): Build a tridiagonal matrix based on lambda values, which will serve as the system's coefficient matrix for the implicit approach.
- Set Up the Right-Hand Side Vector (b) at Each Time Step: Use the temperature values from the previous time step to set up the vector b, incorporating boundary conditions.
- Solve the System and Update Temperatures: Solve the matrix equation '' to get the temperature distribution, updating the results for each time step.
Lamda = (delta_t)/(delta_x^2);
T(i,1) = 200*(i-1)*delta_x*sin(pi*(i-1)*delta_x);
b(i) = b(i) + r * T(1, n+1);
b(i) = b(i) + r * T(M+1, n+1);
T(i, n+1) = solution(i-1);
plot(x, T(:,end), 'b-', 'LineWidth', 2)
title('Temperature Distribution (Implicit Method)')
ylabel('Temperature in Kelvin @ Time = 0.1 @ \Delta t = 0.001')