Beruflich Dokumente
Kultur Dokumente
Files:
Matlab Code
PDF Report
Abstract:
In this homework Laplace equation has been solved for a rectangle, all the values on the
boundary has been set to zero except for one third of one of the sides
Laplace Equation:
∂ 2u ∂ 2u
+ =0
∂x 2 ∂y 2
Decartelization:
U i +1, j − 2U i , j +U i −1, j U i , j +1 − 2U i , j +U i , j −1
+ =0 O ((∆x) 2 , ( ∆y ) 2 )
( ∆x ) 2
( ∆y ) 2
Approach:
Since in the former homework I faced some difficulties with Fortran and I was afraid of
using it again, I chose MATLAB to solve this problem
Inputs
Number of the nodes in x and y direction will be given to the program as inputs
User will be asked if he wants to set the boundary conditions on the middle of the line or
on the corner
And the desired maximum error will be asked as well
For boundary conditions the default mode is on the corner and for the maximum error the
default mode is .00001. User can change them if he wants
Matlab Code:
% Siamak Faridani
% Oct 2, 2006
clc;
clear all;
close all;
maxr=1;
errormatrix=zeros(M,N);
itteration=0;
while maxr>maxerr
for i=2:M-1
for j=2:N-1
tempval=mymatrix(i,j);
mymatrix(i,j)=(mymatrix(i+1,j)+mymatrix(i-
1,j)+mymatrix(i,j+1)+mymatrix(i,j-1))/4;
errormatrix(i,j)=abs(mymatrix(i,j)-tempval);
end
end
maxr=max(max(errormatrix));
itteration=itteration+1;
end
Middle
A 100×100 grid
2500
2257
2000
1500
Iterations
1000
866
500
394
189
0 53
0 20 40 60 80 100 120
N (NxN grid)