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.

2 0 -5 -6 3];A = sparse ( Afull );b = [8 ; 45; -3; 3; 19; -5; 8];x = A\bnorm (A*x-b)The previous script produces the following output.-->x = A\bx =- 0.30947322.96633710.75193681.61231397.0851981--> norm (A*x-b)ans =3.2147514The sparse backslash opera<strong>to</strong>r \ is based on the lufact and lusolvefunctions. It is implemented with overloading. For example, the %sp_l_spfunction provides the operation A\b, where both A and b are sparse.3.3 Iterative methods for sparse linear equationsThe pcg function is a precondioned conjugate gradient algorithm for symmetricpositive definite matrices. It can managed dense or sparse matrices,but is mainly designed for large sparse systems of linear equations. It is basedon a <strong>Scilab</strong> port of the Matlab scripts provided in [1].<strong>In</strong> the following example, we define a dense, well-conditionned 10 × 10dense matrix A and a right hand size b made of ones. We use the sparsefunction <strong>to</strong> convert the A matrix in<strong>to</strong> the sparse matrix Asparse. We finallyuse the pcg function on the sparse matrix Asparse in order <strong>to</strong> solve theequations Ax = b. This produces the solution x, a status flag fail, therelative residual norm err, the number of iterations iter and the vec<strong>to</strong>r ofthe residual relative norms res.A=[ 94 0 0 0 0 28 0 0 32 00 59 13 5 0 0 0 10 0 00 13 72 34 2 0 0 0 0 650 5 34 114 0 0 0 0 0 550 0 2 0 70 0 28 32 12 028 0 0 0 0 87 20 0 33 013

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

Saved successfully!

Ooh no, something went wrong!