Successfully reported this slideshow.
Upcoming SlideShare
×

# FDM Numerical solution of Laplace Equation using MATLAB

12,188 views

Published on

Finite Difference Method Numerical solution of Laplace Equation using MATLAB. 2 computational methods are used.
U can vary the number of grid points and the boundary conditions

Published in: Engineering, Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### FDM Numerical solution of Laplace Equation using MATLAB

1. 1. Numerical Analysis Visit my BlogSpot http://ayaozaki.blogspot.com/2014/06/ fdm-numerical-solution-of-laplace.html 6/25/2014 Aya Zaki 1
2. 2. A Finite Difference Method for Laplace’s Equation • A MATLAB code is introduced to solve Laplace Equation. • 2 computational methods are used: – Matrix method – Iteration method • Advantages of the proposed MATLAB code: – The number of the grid point can be freely chosen according to the required accuracy. – The boundary conditions can simply be changed. 6/25/2014 Aya Zaki 2
3. 3. A Finite Difference Method for Laplace’s Equation (cont.) • Example (Sheet 4) • Grid: N=3 • B.C. shown 6/25/2014 Aya Zaki 3 50 37.5 25 12.5 37.52512.5 000 0 0 0 0 0 200mm 200mm T(i,j)
4. 4. I. Matrix computation method • Example (Sheet 4) • Grid: N=3 • The code generates the equations to be solved: 𝑨 𝑼 = 𝑩 6/25/2014 Aya Zaki 4 k -4 1 0 1 0 0 0 0 0 1 -4 1 0 1 0 0 0 0 0 1 -4 0 0 1 0 0 0 1 0 0 -4 1 0 1 0 0 0 1 0 1 -4 1 0 1 0 0 0 1 0 1 -4 0 0 1 0 0 0 1 0 0 -4 1 0 0 0 0 0 1 0 1 -4 1 0 0 0 0 0 1 0 1 -4 0 0 -12.5 0 0 -25. 0 -12.5 -25.0 -75.0 T11 T21 T31 T21 T22 T23 T31 T32 T33 =
5. 5. U = inv(A)*B; %Re-arrange for j= 1:N for i=1:N T(j+1,i+1)= U((j- 1)*N+i); end end for i= 1:N for j=1:N k= (j-1)*N +i; A(k,k)= -4; for m = i-1: 2:i+1 if ((m<1) ||(m>N)) B(k)= B(k) -T(m+1,j+1); else l = (j-1)*N+m; A(k,l)= 1; end end for n = j-1: 2:j+1 if ((n<1) ||(n>N)) B(k)= B(k)- T(i+1,n+1); else l = (n-1)*N+i; A(k,l)= 1; end end end end I. Matrix computation method(cont.) • Code 6/25/2014 Aya Zaki 5 N=3; T = zeros(N+2, N+2); x = linspace(0,200e-3, N+2); y = linspace(0,200e-3, N+2); %Boundary Conditions % Y- left T(:,N+2) = linspace(0,50,N+2) % Top T(N+2,:)= linspace(0,50,N+2) A , B
6. 6. • T= I. Matrix computation method(cont.) 6/25/2014 Aya Zaki 6 0 0 0 0 0 0 3.125 6.25 9.375 12.5 0 6.25 12.5 18.75 25 0 9.375 18.75 28.125 37.5 0 12.5 25 37.5 50 50 37.5 25 12.5 37.52512.5 000 0 0 0 0 0 3.125 6.25 9.375 6.25 9.375 12.5 18.75 18.75 28.125
7. 7. I. Matrix computation method(cont.) 6/25/2014 Aya Zaki 7 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed with solving the Matrix. Distance y surf(x,y,T); • Plotting T
8. 8. • Plotting T I. Matrix computation method(cont.) 6/25/2014 Aya Zaki 8 contour(x,y,T); Temperature plot (contourf) 0 0.05 0.1 0.15 0.2 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0 5 10 15 20 25 30 35 40 45
9. 9. • N= 50 I. Matrix computation method(cont.) 6/25/2014 Aya Zaki 9 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed with solving the Matrix. Distance y
10. 10. for k=1:20 for i=2:N+1 for j=2:N+1 un(i,j)=(un(i+1,j)+un(i-1,j)+un(i,j+1)+un(i,j-1))/4; end end end II. Iteration computation method • Code – Number of iterations = 20 – The better the initial guess, the faster the computation is. – For simplicity, the initial value for all points is chosen as zero. 6/25/2014 Aya Zaki 10 N=3; T = zeros(N+2, N+2); x = linspace(0,200e-3, N+2); y = linspace(0,200e-3, N+2); %Boundary Conditions % Y- left T(:,N+2) = linspace(0,50,N+2) % Top T(N+2,:)= linspace(0,50,N+2)
11. 11. • T= II. Iteration computation method (cont.) 6/25/2014 Aya Zaki 11 0 0 0 0 0 0 3.125 6.25 9.375 12.5 0 6.25 12.5 18.75 25 0 9.375 18.75 28.125 37.5 0 12.5 25 37.5 50
12. 12. • Plotting T II. Iteration computation method (cont.) 6/25/2014 Aya Zaki 12 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed with 20 iteration. Distance y The same results were obtained as before. 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50
13. 13. • Plotting T II. Iteration computation method (cont.) 6/25/2014 Aya Zaki 13 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed with 20 iteration. Distance y The same results were obtained as before. 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50
14. 14. • Plotting T II. Iteration computation method (cont.) 6/25/2014 Aya Zaki 14 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed with 20 iteration. Distance y The same results were obtained as before.
15. 15. A Finite Difference Method for Laplace’s Equation (cont.) • Example (Sheet 4) • Grid: N=3 • B.C. with lower edge insulated. 6/25/2014 Aya Zaki 15 50 37.5 25 12.5 37.52512.5 000 0 0 0 0 0 200mm 200mm T(i,j)
16. 16. Lower Edge Insulated • Example (Sheet 4) • Grid: N=3 • B.C. with lower edge insulated. 6/25/2014 Aya Zaki 16 50 37.5 25 12.5 37.52512.5 0 0 0 0 T 0 5.0367 8.6453 8.6450 0 0 5.7508 10.4498 12.9673 12.5000 0 7.5166 14.4358 20.2743 25.0000 0 9.8797 19.5024 28.6942 37.5000 0 12.5000 25.0000 37.5000 50.0000
17. 17. Lower Edge Insulated • Plot of T 6/25/2014 Aya Zaki 17 N =3 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed. Distance y
18. 18. Lower Edge Insulated • N = 100 6/25/2014 Aya Zaki 18 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance x Numerical solution computed. Distance y 0 0.05 0.1 0.15 0.2 0 10 20 30 40 50 Distance y Temperature(C) Plot of Temperature at different x points 0mm 100mm 200mm
19. 19. Lower Edge Insulated • N = 100 6/25/2014 Aya Zaki 19 Temperature plot (contourf) 0 0.05 0.1 0.15 0.2 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0 5 10 15 20 25 30 35 40 45