[ Home ] | Linear algebraic equations | Numerical Methods. Note « 2 » |
Haskell | C | C++ |
a = [[i+j | i <- [1..n] ] | j <- [1..n]] |
float **a = (float **)malloc(n*sizeof(float *)); for ( i=0; i<n ; i++ ) a[i] = (float *)malloc(n*sizeof(float)); a[0][0]=1; ...; QR(a,n); ... |
A=new double*[m]; for(i=0; i<m; i++) A[i]=new double[n]; a[0][0]=1; ...; QR(A,n); ... |
for i=1:m Ri,i=√(a(i)⋅a(i)); q(i)=a(i)/Ri,i #normalization for j=i+1:m Ri,j=q(i)⋅a(j); a(j)=a(j)-q(i)Ri,j #orthogonalizationThe matrix Q made of columns q(i) is orthogonal, R is right triangular and A = QR.
QR back-substitution is a method to solve the linear system QRx=b by transforming it into a triangular system Rx=QTb
b = QTb for i = m: -1: 1 xi = (bi - ∑k=i+1,m Ri,k xk)/Ri,i
LU decomposition is the decomposition of a matrix A into a product of a lower triangular matrix L and an upper triangular matrix U, A = LU. The equation Ax=b, ie LUx=b, can then be solved by first solving for Ly=b and then for Ux=y by two runs of backward and forward substitutions.
Determinant of a triangular matrix is a product of its diagonal elements.
Problems