0% found this document useful (0 votes)
50 views2 pages

'Enter The Domain Length:' '/nenter The Number of Grid Points:'

The document describes a MATLAB function that solves a 1D heat equation on a grid. It takes user inputs for the domain length and number of grid points. It then sets up the tridiagonal matrix and performs forward and backward substitution to solve for the temperature values at each point. Finally, it plots the temperature profile across the domain and outputs a table of x and T values.

Uploaded by

Sanket Shah
Copyright
© Attribution Non-Commercial (BY-NC)
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)
50 views2 pages

'Enter The Domain Length:' '/nenter The Number of Grid Points:'

The document describes a MATLAB function that solves a 1D heat equation on a grid. It takes user inputs for the domain length and number of grid points. It then sets up the tridiagonal matrix and performs forward and backward substitution to solve for the temperature values at each point. Finally, it plots the temperature profile across the domain and outputs a table of x and T values.

Uploaded by

Sanket Shah
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

6/2/13 7:22 PM

C:\Users\SANKET\Desktop\CFDHT\assgn1\examp...\sanket_amit_2.m

function sanket_amit_2()
clc;
l=input('Enter the domain length:');
n=input('\nEnter the number of grid points:');
dx=l/(n-1);
%Calculating the Diagonal elements
for i=2:n-1
a(i,i)=-2;
a(i,i+1)=1;
a(i,i-1)=1;
b(i)=-1600000*(dx*dx);
end
b(2)=-100-1600000*(dx*dx);
b(n-1)=-200-1600000*(dx*dx);
%forward elimination
for i=3:n-1
a(i,i)=a(i,i)-(a(i,i-1)*a(i-1,i)/a(i-1,i-1));
b(i)=b(i)-(a(i,i-1)*b(i-1)/a(i-1,i-1));
end
%Backward substitution
w(n)=0;
a(n-1,n)=0;
for i=n-1:-1:2
w(i)=(b(i)-a(i,i+1)*w(i+1))/a(i,i);
end
%Calculating the T values
for i=2:n-1
T(i)=w(i);
end
T(1)=100;
T(n)=200;
%Calculating the x values
x(1)=0;
for i=2:n
x(i)=x(i-1)+dx;
end
%Plotting and tabulating
Temp_table=[x;T]'
plot(x,T);
xlabel('x');
ylabel('T(x)');
end

1 of 1

6/2/13 7:22 PM

MATLAB Command Window

Enter the domain length:0.02


Enter the number of grid points:20
Temp_table =
0
0.0011
0.0021
0.0032
0.0042
0.0053
0.0063
0.0074
0.0084
0.0095
0.0105
0.0116
0.0126
0.0137
0.0147
0.0158
0.0168
0.0179
0.0189
0.0200
>>

100.0000
121.2188
140.6648
158.3380
174.2382
188.3657
200.7202
211.3019
220.1108
227.1468
232.4100
235.9003
237.6177
237.5623
235.7341
232.1330
226.7590
219.6122
210.6925
200.0000

1 of 1

You might also like