Hi Gabriel Quattromani,
I understand that you are facing some issues in implementing the code for transient conduction.
Please find the below modifications.
The initial temperature profile should be “T_ini” throughout the soil depth, except at the surface which is exposed to the air temperature “T_inf”. The original code incorrectly set the initial temperatures for the interior nodes to “T_inf”.
The original code incorrectly set the boundary condition at the bottom of the domain to “T_inf”. The modification ensures that the bottom boundary condition is insulated or set to the initial soil temperature “T_ini”.
- Matrix assembly and time-stepping:
The tridiagonal matrix should be assembled once outside the time loop, and at each time step, the system “Ai * Ti(:,j+1) = d” should be solved to update the temperature profile. The modified code correctly assembles the tridiagonal matrix and performs the time-stepping loop to solve for the temperature at each time step.
Here is the complete code.
a = (1 + 2*alpha*DELTA_t/DELTA_x^2) * ones(N+1, 1);
b = (-alpha*DELTA_t/DELTA_x^2) * ones(N+1, 1);
Ai = diag(a) + diag(b(2:end), -1) + diag(c(1:end-1), 1);
plot(depths, Ti(:,end), 'b');
ylabel('Temperature (C)');
title('Temperature profile after 60 days');
Hope this solution helps.
Thanks,
Ravi Chandra