Está en la página 1de 9

Assignment 3

Rajarshi Guha, Vishal Dalvi and Rahul Kumar


M.Tech. 2nd year, 07302009, 07302005 and 07302006
Modeling & Simulation, CL676

Monte Carlo Simulation of 2 dimensional Laplace Equation:

10 x 10 Temperature Grid:

400 500 500 500 500 500 500 500 500 400
300 330 340 420 440 500 420 440 500 300
300 310 300 480 300 400 500 420 300 300
300 310 450 310 310 300 380 410 340 300
300 330 360 400 470 410 380 360 430 300
300 440 350 360 350 420 320 320 300 300
300 420 340 460 410 300 310 310 470 300
300 410 400 480 340 370 320 440 450 300
300 360 350 380 400 410 440 440 380 300
400 500 500 500 500 500 500 500 500 400

500

480

460

440

420

400

380

360

340
10
320
8
300 6
10
9 4
8
7
6 2
5
4
3
2 0
1

Fig.1. 3-dimensional plot of grid point temperatures using MC simulation in MATLAB.


Walls are at temperatures 300 & 500 K with the corner points having 400K.
Finite Difference Simulation of 2 dimensional Laplace Equation:

10 x 10 Temperature Grid:

500

480

460

440

420

400

380

360

340

320

300 10
10 9
9 8
8 7
7 6
6 5
5 4
4 3
3 2
2
1 1

Fig.2. 3-dimensional plot of grid point temperatures using FD simulation in MATLAB.


Walls are at temperatures 300 & 500 K with the corner points having 400K.
Monte Carlo Simulation of 2 dimensional Laplace Equation:

10 x 10 Temperature Grid:

500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500
500 500 500 500 500 500 500 500 500 500

501

500.8

500.6

500.4

500.2

500

499.8

499.6

499.4
10
499.2
8
499
10 6
9
8
7 4
6
5
4 2
3
2
1 0

Fig.3. 3-dimensional plot of grid point temperatures using MC simulation in MATLAB.


Wall temperatures are at 500K throughout.
Finite Difference Simulation of 2 dimensional Laplace Equation:

10 x 10 Temperature Grid:

600

550

500

450

400

350

300
10
9
8

7
6

5 10
9
4 8
7
3 6
5
2 4
3
1 2
1

Fig.4. 3-dimensional plot of grid point temperatures using MC simulation in MATLAB.


Wall temperatures are at 500K throughout.
Simulation with MC and FD with different Boundary Temperatures: The below figures
are for Boundary Temperatures of 500 & 800 K with corners are at 500, 600, 650 &
700K.

800

750

700

650

600

550 10

8
500
6
10
9
8 4
7
6
5 2
4
3
2 0
1

800

750

700

650

600

550

500
10
9 1
8 2
7 3
6 5 4
5 6
4 7
3 8
2 9
1 10
Appendix:

Coding:

1. Monte Carlo Simulation:

% Defining the boundary points


for i=1:10
for j=1:10
if(i==1||i==10||j==1||j==10)

C(1,:)=500;
C(10,:)=500;
C(:,1)=300;
C(:,10)=300;
C(1,1)=400;
C(1,10)=400;
C(10,1)=400;
C(10,10)=400;
else
C(i,j)=0;
end
end
end
%C;

% Taking intermediate grid points and iterating


for i=2:9
for j=2:9
x=i;
y=j;
avgT=0;

for m=1:10000

conv=1;

while(conv>0)

% 2-dimensional Random Walk


r = rand(1,1);

if(r < 0.25)


x=x-1;
elseif (r < 0.50)
x=x+1;

elseif (r < 0.75)


y=y+1;

else
y=y-1;

end

if(x<1 || x>10 || y<1 || y>10)


if(x<=1)
x=x+1;
end
if(y<=1)
y=y+1;
end
if(x>=10)
x=x-1;
end
if(y>=1)
y=y-1;
end
continue;
end

% Whether boundary is reached

if(C(x,y)==300 || C(x,y)==400|| C(x,y)==500)


d(m)=C(x,y);
break;
else
continue;
end

end

avgT=avgT+d(m);
if(m==10)
C(i,j)=avgT/m;
end

end
end
end
% Plotting the Mesh

for i=1:10
for j=1:10
Px(i)=i;
Py(j)=j;
Temp(i,j)=C(i,j);
end
end
Temp
mesh(Px,Py,Temp)

2. Finite Difference Simulation:

a. Function File:

function f = laplace_eqn(Tn)

v=Tn;
for i=2:9
for j=2:9
v(i,j)=0.25*(v(i-1,j)+v(i+1,j)+v(i,j+1)+v(i,j-1));
end
end

f=v;

b. Main file:

for i=1:10
for j=1:10
if(i==1||i==10||j==1||j==10)

C(1,:)=500;
C(10,:)=500;
C(:,1)=300;
C(:,10)=300;
C(1,1)=400;
C(1,10)=400;
C(10,1)=400;
C(10,10)=400;
else
C(i,j)=450;
end
end
end

% Running the iterations until consecutive matrix difference norm becomes less than
tolerance

for i=1:50000
Co=C;
soln=feval('laplace_eqn',C);
Cn=soln;
C=soln;
if(norm(Cn-Co)<.01)
break;
end

end
norm(Cn-Co)
Temp=C;

for i=1:10
for j=1:10
Px(i)=i;
Py(j)=j;
Temp(i,j)=C(i,j);
end
end
Temp
mesh(Px,Py,Temp)

También podría gustarte