Find answers, ask questions, and connect with our <br>community around the world.

Home Forums CFD foundation course: Forum Lesson 19 1D steady state heat conduction (FVM).

• # Lesson 19 1D steady state heat conduction (FVM).

Posted by on January 8, 2024 at 11:15 pm

Hi,

I tried to write the Matlab program for the Lesson 19 1D steady state heat conduction (FVM).
As per the lecture, the solution should be T1=140; T2=220; T3=300; T4=380; T5=460.
But my results are wrong. I spent 2 days and tried in different ways to write the same program, but I got error.
It would be helpful if you can support me to get the correct result.

Thank you.

L = 0.5; %Length of rod

N = 5; %Number of cells

dx = L/N;

Tl = 100; %Left side temperature

Tr = 500; %Right side temperature

k = 1000; %Thermal conductivity

A = 10e-2; %Area

T = zeros(N, 1);

Am = zeros(N, N); %Coefficient matrix)

b = zeros(N, 1);%vector

for i = 1:N

if i == 1 %at cell 1

Am(i, i) = 3*k*A/dx;

Am(i, i+1) = -k*A/dx;

b(i) = Tl*k*A/dx;

elseif i >= 2 && i <= N-1

Am(i, i-1) = -k*A/dx;

Am(i, i) = 2*k*A/dx;

Am(i, i+1) = -k*A/dx;

b(i) = 0;

elseif i == N %at cell N

Am(i, i-1) = -k*A/dx;

Am(i, i) = 3*k*A/dx;

b(i) = Tr*k*A/dx;

end

end

T = Am\b;

fprintf(‘Node\tTemperature\n’);

fprintf(‘—————-\n’);

for i = 1:N

fprintf(‘%d\t%.2f\n’, i, T(i));

end

plot(linspace(0, L, N), T);

xlabel(‘Position (m)’);

ylabel(‘Temperature’);

title(‘Temperature Distribution’);

grid on;

• ### Sujith FTL

Member
January 9, 2024 at 9:49 am

Hello. I could figure out some errors from your code which are mostly syntax based:

1. There are syntax errors in the fprintf function calls for printing headers and temperatures. Correct the opening and closing quotes.

2. Additionally, fix the typo in the title function.

3. Ensure consistent usage of the variable dx for cell size throughout the code.

4. The plot function call has a small mistake.

To debug the logical errors, please go through the original example given in the book from which this problem is taken to see the workflow they have taken.

Regards,

Sujith