#https://www.youtube.com/watch?v=PE7oiOq_xig
#MATLAB code for solving Laplace's equation using the Jacobi method
clear
clc
Nx = 5;
Ny = 4; % nodes number in y directionn
tol = 1d - 6; %tolerence
k = 0; % iteration counter
%define u array
u = [8.9,8.9,8.9,8.9,8.9;
8.4,0.0,0.0,0.0,9.2;
7.2,0.0,0.0,0.0,9.4;
6.1,6.8,7.7,8.7,6.1];
ukpl = u;
while err > tol
k = k + 1;
for j = 2 : Ny - 1
for i = 2 : Nx - 1
ukpl(j,i) = 0.25 * (u(j+1,i) + u(j,i+1) + u(j-1,i) + u(j,i - 1));
end
end
err = sqrt(sum(sum(ukpl - u)^2));
u = ukpl;
end