0% found this document useful (0 votes)
18 views1 page

4/7/21 2:22 AM D:/matlab Term3/ex - Soldiffwith - BC.M 1 of 1: For End

This document defines the parameters and discretization for a finite difference method to solve the 1D steady-state heat equation with boundary conditions on a metal rod. It defines the geometry, known temperatures, coefficient matrix, and solves the system of equations to find the temperature at each node.

Uploaded by

Tom Ammaly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

4/7/21 2:22 AM D:/matlab Term3/ex - Soldiffwith - BC.M 1 of 1: For End

This document defines the parameters and discretization for a finite difference method to solve the 1D steady-state heat equation with boundary conditions on a metal rod. It defines the geometry, known temperatures, coefficient matrix, and solves the system of equations to find the temperature at each node.

Uploaded by

Tom Ammaly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

4/7/21 2:22 AM D:\matlab term3\ex_soldiffwith_BC.

m 1 of 1

clear all
clc
%% define the known information
h = 0.01; %heat transfer coeficient
Ta = 20; %Surrounding temp
T0 = 200; %B.C.1: T(x=0)==200
Tn = 40; %B.C.2: T(x=L)=40
L = 10; %length of the metal rod

%% Discretization
x0 = 0; %Initial x, x=0
dx = 2; %Step size
seg = L/dx; %Number of segment
n = seg+1 %total number of node
xn = L; %Final x, x = L

%% Location of interior nodes


x(1) = x0; %locate the position of the first node
x(n) = xn; %locate the position of the final node
for i = 2:n-1
x(i) = x(i-1)+dx; %1st loop x(2)=x(1)+dx
end
%disp(x)

%% Create matrix of coefficent [A]


A(1,1) = -(2+(dx^2)*h); %A11
A(1,2) = 1; %A12
b(1) = -T0-((dx^2)*h*Ta);%b1

j = 2; %index of the column


for i = 2:n-3
A(i,j-1) = 1;
A(i,j) = -(2+(dx^2)*h); %Diagonal element
A(i,j+1) = 1; %rigth element
b(i) = -((dx^2)*h*Ta); %b
j = j+1 %update column index
end
A(n-2,n-3) = 1; %the first element of the final row
A(n-2,n-2) = -(2+(dx^2)*h); %the final elemnt in [A]
b(n-2) = -Tn-((dx^2)*h*Ta); %the final element in [B]

disp(A)
disp(b)

T = A\b'
disp(T)

You might also like