function dirichlet(bfun,n,tol,maxk,metoda) % dirichlet(bfun,n,tol,maxk,metoda) izracuna % obliko milnice na kvadratu [0,1]x[0,1], % ce so podane robne vrednosti % n+2 je stevilo delilnih tock na eni koordinatni osi % bfun je funkcija, ki vrnejo vrednosti na robu [0,1]x[0,1] % parametre maxk in tol podamo funkciji laplace % metoda je stikalo, ki pove ali zelimo: %'Jacobi'=Jacobijevo iteracijo %'Gauss-Seidel'=Gauss-Seidelovo iteracijo %'SOR'=SOR iteracijo % nazadnje narise graf milnice % % computes and plots the approximate solution % to the Dirichlet problem on D=[0,1]x[0,1] % n+2 is the number of points in each direction % bfun is the function defined on the boundary of D % the parameters maxk and tol are arguments needed to % terminate the iterative methods used % 'metoda' is used for the switch where the iterative method used is % choosed: % 'Jacobi'=Jacobi iteration % 'Gauss-Seidel'=Gauss-Seidelovo iteration % 'SOR'=SOR iteration % 'Jacobi-matrix' = Jacobi iteration using matric operations instead of % for loops x=linspace(0,1,n+2);%argumenti za bfun / argument for bfun [zgoraj spodaj levo desno]=testfunction(x);%izracun ribne funkcije / compute the boundary function U=[spodaj; levo(2:n+1)' zeros(n) desno(2:n+1)'; zgoraj];%sestavimo zacetni priblizek / constructing initial approximation tic switch metoda case 'jacobi' [U,k]=laplace_jac(U,tol,maxk); case 'gs' [U,k]=laplace_gs(U,tol,maxk); case 'sor' [U,k]=laplace_sor(U,tol,maxk,1.87); case 'jacobi-matrix' [U,k]=laplace_jac_mat(U,tol,maxk); end surf(x,x,U);%narisemo ploskev / draw surface toc stevilo_iteracij=k