'Enter The Domain Length:' '/nenter The Number of Grid Points:'
'Enter The Domain Length:' '/nenter The Number of Grid Points:'
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
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