11.07.2015 Views

Introduction to Sparse Matrices In Scilab - Projects

Introduction to Sparse Matrices In Scilab - Projects

Introduction to Sparse Matrices In Scilab - Projects

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The solver argument is designed so that we can cus<strong>to</strong>mize the linear equationsolver which we want <strong>to</strong> use. For example, if we want <strong>to</strong> use the sparsebackslash opera<strong>to</strong>r, all we have <strong>to</strong> do is <strong>to</strong> create the mysolverBackslashfunction as below.function u= mysolverBackslash (N, b)A = scibench_poissonA (N);u = A\b;endfunctionThe following script solves the Poisson equation with N = 50.scf ();scibench_poisson (50 , %t , %t , mysolverBackslash );The previous script produces the following output, where h is the dimensionnalspacee step and enorminf is the value of the infinite norm of the error.-> scibench_poisson (50 , %t , %t , mysolverBackslash );N = 50h = 1.9607843137254902 e -002h^2 = 3.8446751249519417 e -004enorminf = 1.2634082165868810 e -003C = enorminf / h^2 = 3.2861247713424775 e +000wall clock time = 0.15 secondsThe previous script also produces the plot in the figure 13.It is then easy <strong>to</strong> use the pcg function built in <strong>Scilab</strong>, which uses a preconditionnedconjugate gradient algorithm. We use the scibench_poissonAufunction, which computes the A*u product without actually s<strong>to</strong>ring the matrixA.function u= mysolverPCG (N, b)<strong>to</strong>l = 0.000001;maxit = 9999;u = zeros (N ^2 ,1);[u,flag ,iter , res ] = ..pcg ( scibench_poissonAu ,b,<strong>to</strong>l , maxit ,[] ,[] ,u);endfunctionscf ();[ timesec , enorminf ,h] = ..scibench_poisson (50 , %f , %t , mysolverPCG );30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!