Vous êtes sur la page 1sur 6

5/2/13 4:36 PM

C:\Users\SANKET\Desktop\CFDHT\assgn1\sanket_amit_4.m

1 of 2

function sanket_amit_4()
clc;
clear;
del_x=0.05;
del_y=del_x;
B=(del_x/del_y);
A=1/(2*(1+B^2));
fprintf('Enter the initial guess for the temparature: ');
a=input('');
h=2;
l=1;
nx=(l/del_x);
ny=(h/del_y);
%specifying the initial guess
for i=2:nx
for j=2:ny
u(i,j,1)=a;
end
end
%k is the iterating variable
k=1;
while 1
%Boundary conditions
for j=1:ny+1
u(1,j,k)=100;
u(nx+1,j,k)=0;
u(1,j,k+1)=100;
u(nx+1,j,k+1)=0;
end
for i=1:nx+1
u(i,1,k)=0;
u(i,ny+1,k)=0;
u(i,1,k+1)=0;
u(i,ny+1,k+1)=0;
end
%algorithm
for i=2:nx
for j=2:ny
u(i,j,k+1)=A*(u(i+1,j,k)+u(i-1,j,k+1)+(B^2)*u(i,j+1,k)+(B^2)*u(i,j-1,
k+1));
end
end
%Calculating and checking the error
for i=2:nx
for j=2:ny
o(i,j)=abs(u(i,j,k+1)-u(i,j,k));
end
end
q=max(o);
if q<0.001
break

5/2/13 4:36 PM

C:\Users\SANKET\Desktop\CFDHT\assgn1\sanket_amit_4.m

end
k=k+1;
end
fprintf('The number of iterations for convergence:%d',k);
%calculation of the X and Y co-ordinates
x(1)=0;
y(1)=0;
for i=1:nx
x(i+1)=x(i)+del_x;
end
for i=1:ny
y(i+1)=y(i)+del_y;
end
%Replaces u by T
for i=1:nx+1
for j=1:ny+1
T(i,j)=u(i,j,k);
end
end
%Tabulation and plotting
Temp_table=T'
contour(x,y,T')
xlabel('X');
ylabel('Y');
zlabel('T(x,y)');
end

2 of 2

4/2/13 6:22 PM

MATLAB Command Window

1 of 1

Enter the initial guess for the temparature: 50


The number of iterations for convergence:37
Temp_table =
0
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
0
>>

0
47.7862
65.3817
72.5610
75.5251
76.3437
75.5246
72.5600
65.3806
47.7854
0

0
25.7620
41.1781
49.3353
53.1941
54.3235
53.1933
49.3340
41.1766
25.7609
0

0
14.0825
24.2316
30.4063
33.5906
34.5613
33.5899
30.4050
24.2303
14.0815
0

0
6.3353
11.2584
14.4661
16.1993
16.7399
16.1989
14.4654
11.2577
6.3348
0

0
0
0
0
0
0
0
0
0
0
0

1.8

1.6

1.4

1.2

0.8

0.6

0.4

0.2

0
0

0.1

0.2

0.3

0.4

0.5
X

0.6

0.7

0.8

0.9

5/2/13 5:18 PM

C:\Users\SANKET\Documents\MATLAB\analytical4.m

1 of 1

clc;
del_x=0.20;
del_y=del_x;
h=2;
l=1;
nx=(l/del_x);
ny=(h/del_y);
x(1)=0;
y(1)=0;
for i=1:nx
x(i+1)=x(i)+del_x;
end
for i=1:ny
y(i+1)=y(i)+del_y;
end
for j=2:ny
for i=2:nx
m=1;
sum=0;
while 1
sum1=sum+((1-((-1)^m))/(m*3.142))*(sinh(m*3.142*0.5*(l-x(i)))/sinh(3.142*0.5*m))
*sin(3.142*0.5*m*y(j));
error=abs(sum1-sum);
if error<0.01
break
end
m=m+2;
sum=sum1;
end
T_anal(i,j)=200*sum1;
end
end
for i=1:nx+1
for j=2:ny
T_anal(1,j)=100;
T_anal(nx+1,j)=0;
end
T_anal(i,1)=0;
T_anal(i,ny+1)=0;
end
Temp_Table=T_anal'

5/2/13 5:17 PM

MATLAB Command Window

1 of 1

Temp_Table =
0
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
0
>>

0
47.8958
68.2151
72.6941
75.2278
76.8964
75.2221
72.6865
68.2027
47.8527
0

0
24.9000
41.4950
50.6913
53.4846
54.8832
53.4811
50.6843
41.4799
24.8720
0

0
13.4463
24.1342
30.7646
33.8326
34.8643
33.8303
30.7586
24.1234
13.4302
0

0
6.1306
11.1732
14.5486
16.3134
16.8355
16.3120
14.5453
11.1677
6.1231
0

0
0
0
0
0
0
0
0
0
0
0

Vous aimerez peut-être aussi