You are on page 1of 1

% matlab program of laplace equation

n = input('Enter no. of mesh point in x -direction: ');


m = input('Enter no of mesh point in y - direction:');
for j = m : -1:1
for i = 1:n
u(i,j) = 0;
end
end

fprintf('Enter boundary valve (B,V) in anticlockwise direction starting from bottom


left corner\n');
for i = 1 : n
fprintf('Enter u(%d,1)=',i);
u(i,1) = input(' ');
end
for j = 2:m
fprintf('Enter u(%d,%d)=',n,j);
u(n,j) = input('');
end
for i = n-1:-1:1
fprintf('Enter u(%d,%d)=',i,m);
u(i,m) = input(' ');
end
for j=m-1:-1:2
fprintf('Enter u(1,%d)=',j);
u(1,j) = input(' ');
end

p = input('Enter no. of interation:');

for k =1:p
for j = m-1:-1:2
for i = 2:n-1
u(i,j) = 1/4*(u(i-1,j)+u(i,j+1)+u(i+1,j)+u(i,j-1));
end
end
end

fprintf('value after iteration no. : %d\n',p);

for j =m:-1:1
for i = 1:n
fprintf('\t %0.4f',u(i,j));
end
fprintf('\n');
end

You might also like