• 검색 결과가 없습니다.

Sparse Matrix

N/A
N/A
Protected

Academic year: 2021

Share "Sparse Matrix"

Copied!
11
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

Sparse Matrix

Wanho Choi (wanochoi.com)

(2)

Two-point boundary value problem example

′′

y (x)

= f (x) on[0,1] with y(0) = y(1) = 0

from PDE to Matrix Eqn.

x = 0 x = 1

Given)

1) the curvature values as a function 2) the values of two end points

To solve)

h = Δx

(3)

Two-point boundary value problem example

′′

y (x)

= f (x) on[0,1] with y(0) = y(1) = 0

from PDE to Matrix Eqn.

′′ yi = ′yi+0.5 − ′yi−0.5 h = yi+1 − yi hyi − yi−1 h h = yi−1 − 2yi + yi+1 h2 = fi

by FDM (Finite Difference Method)

∴−yi−1 + 2yi − yi+1 = −h2

fi

(i = 0,1,2,!,n −1)

(4)

Two-point boundary value problem example

′′

y (x)

= f (x) on[0,1] with y(0) = y(1) = 0

from PDE to Matrix Eqn.

−y0 + 2y1 − y2 = −h2 f1 2y0 − y0 = −h2 f0 from − yi−1 + 2yi − yi+1 = −h2 fi −y1 + 2y2 − y3 = −h2 f2 −yn−3 + 2yn−2 − yn−1 = −h2 fn−2 −yn−2 + 2yn−1 = −h2 fn−1 ! 2 −1 0 −1 2 −1 0 0 0 0 0 0 0 0 0 0 0 0 −1 2 −1 −1 2 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ! ! ! ! ! ! ! ! ! ! ! y0 y1 ! yn−2 yn−1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ = −h2 f0 −h2 f1 ! −h2 fn−2 −h2 fn−1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥

tridiagonal matrix equation Ax=b

(5)

Globally coupled system

But, only directly related to adjacent elements because the derivatives are estimated from the neighboring elements

So, the final system becomes a sparse matrix equation.

For physical problems, the matrix is symmetric due to the law of action and reaction.

And, in most cases, the matrix is diagonal dominant and (semi) positive-definite.

(6)

A matrix in which most of the elements are zero

The above 4 by 4 matrix contains only 6 non-zero elements, with 10 non-zero elements.

When doing matrix-vector multiplication, 10 multiplying operations has no effects on the result.

Sparse Matrix

2 1 0 0 0 1 0 0 1 0 2 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ x y z w ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = 5 3 7 2 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ (2 × x) + (1× y) + (0 × z) + (0 × w) = 5 (0 × x) + (1× y) + (0 × z) + (0 × w) = 3 (1× x) + (0 × y) + (2 × z) + (0 × w) = 7 (0 × x) + (0 × y) + (0 × z) + (1× w) = 2

(7)

A matrix in which most of the elements are zero

Merits

✓ Lower memory

✓ Lower computations

(8)

Dictionary of keys (DOK)

List of lists (LIL)[edit]

Coordinate list (COO)

Compressed sparse row (CSR)

(9)

The CSR format stores a matrix using three one-dimensional arrays.

✓ v[i]: the value of the i-th non-zero entry size(v) = # of non-zero entries

✓ r[i]: the first non-zero index (v-array index) of the i-th row size(r) = # of rows + 1

✓ c[i]: the column index of the i-th non-zero entry size(c) = non-zero entries

Compressed Sparse Row

2 1 0 0 0 1 0 0 1 0 2 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ float v[] = { 2,1, 1, 1,2, 1 } int r[] = { 0, 2, 3, 5, 6 } int c[] = { 0,1, 1, 0,2, 3 }

(10)

float SparseMatrix::operator()( int i, int j ) const {

const int& r0 = r[i]; const int& r1 = r[i+1];

if( i > j ) { // searching in the lower part

for( int k=r0; k<r1; ++k ) { if( c[k] == j ) { return v[k]; } } } else { // searching in the upper part

for( int k=r1-1; k>=r0; —k ) { if ( c[k] == j ) { return v[k]; } } }

return v[0]; // but, meaningless return }

(11)

참조

관련 문서

In this research, there is no consistent result that the outsourcing can give effects on business performance, but most of hypothesis indicates that

The matrix A show the cost per computer (in thousands of dollars) and B the production figures for the year 2005 (in multiples of 1000 units).. Find a matrix C that

Effects of phase I periodontal treatment on gingival crevicular fluid levels of matrix metalloproteinase-3 and tissue inhibitor of metalloproteinase-1.

No.. 4.24 Effect of solid fuels on the area ratio of Slag, Calcium-Ferrite and Matrix phase of C/S... 4.25 Comparison of Fe 2 O 3 and CaO contents measured by ICP-OES

 자신의 무지와 몰이해에 대해 자책하거나, 일깨움이 더딘 것을 탓하지 말고 그저 부지런히 행함을 놓치지 않는다..  언제나 자신에게 솔직할 것이며, 나눌 준비와

Perform the iteration and estimate the spectral radius of the iteration matrix by computing the ratio of pseudo error norms at each iteration step.. Exit the iteration

After re analysis result YCC and XYS is graph are almost similar by applying reconstructed material properties and stress-strain curve of matrix for GENOA..

 A linear system of equations in n unknowns has a unique solution if the coefficient matrix and the augmented matrix have the same rank n, and infinitely many solution if