Solves the 2D Poisson PDE.
[timesec,enorminf,h] = scibench_poisson ( N , plotgraph , verbose , solver )
a 1-by-1 matrix of doubles, integer values. The number of cells.
a 1-by-1 matrix of booleans. Set to %t to plot the graphics.
a 1-by-1 matrix of booleans. Set to %t to print messages.
a function, the linear equation solver.
a 1-by-1 matrix of doubles, the time to perform the computation (in seconds)
a 1-by-1 matrix of doubles, the L-infinite error norm between the exact solution and the approximated solution
a 1-by-1 matrix of doubles, the size of the step (h = 1/(N+1)).
We compute the numerical solution with finite differences for the Poisson problem with homogeneous Dirichlet boundary conditions. We use Sparse Gaussian Elimination based on the sparse backslash operator.
We consider the 2 dimensional problem Partial Differential Equation:
where the Laplace operator is
We consider the domain 0 <= x1 <= 1, 0 <= x2 <= 1. The function f is defined by f(x, y) = −2pi^2 cos(2pix) sin^2(piy) − 2pi^2 sin^2(pix) cos(2piy). The solution is u(x, y) = sin^2(pix) sin^2(piy). We use a grid of N-by-N points. We use a second order finite difference approximation of the Laplace operator. The solution of the problem is the solution of the linear system of equations
A u = b,
where A is a N^2-by-N^2 matrix. In order to compute the matrix A, we perform the sum of two Kronecker products. The computation of A is fast and produces a sparse matrix A.
Most of the CPU time is consumed by the resolution of the
system of linear equations, within the solver
function.
This function must have header
u = solver(N,b)
stacksize("max"); scf(); function u=mysolverBackslash(N, b) A = scibench_poissonA(N); u = A\b; endfunction [timesec,enorminf,h] = scibench_poisson(50, %t , %t , mysolverBackslash ) // Use a PCG solver: function u=mysolverPCG(N, b) tol = 0.000001; maxit = 9999; u = zeros(N^2,1); [u,flag,iter,res] = pcg(scibench_poissonAu,b,tol,maxit,[],[],u); endfunction [timesec,enorminf,h] = scibench_poisson(50, %f , %t , mysolverPCG ); | ![]() | ![]() |
"A Comparative Evaluation Of Matlab, Octave, Freemat, And Scilab For Research And Teaching", 2010, Neeraj Sharma and Matthias K. Gobbert