# 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

0032 0.0074 0.0042 0.0158 0.9003 237.0084 0.0021 0.02 Enter the number of grid points:20 Temp_table = 0 0.7202 211.4100 235.6/2/13 7:22 PM MATLAB Command Window Enter the domain length:0.0105 0.0053 0.0200 >> 100.0116 0.0000 121.0011 0.5623 235.2188 140.3657 200.0063 0.0168 0.1468 232.0000 1 of 1 .7590 219.1330 226.3380 174.1108 227.0126 0.6122 210.0137 0.0095 0.0189 0.7341 232.6925 200.2382 188.6177 237.0147 0.0179 0.6648 158.3019 220.