<< linalg_gemm blaslapack linalg_zgemm >>

linalg >> linalg > blaslapack > linalg_gesv

linalg_gesv

Computes the real or complex solution X of A*X=B.

Calling Sequence

X = linalg_gesv ( A , B )

Parameters

A :

a n-by-n matrix of doubles (real or complex)

B :

a n-by-p matrix of doubles (real or complex)

X :

a n-by-p matrix of doubles (real or complex), the solution of A*X = B.

Description

Computes the real or complex solution X of A*X=B. Uses BLAS/DGESV if all inputs are real, uses ZGESV if any input is complex. Convert to complex matrices when necessary to call ZGESV.

The solution of A*X=B in Scilab is based on the backslash operator. The backslash operator is switching from Gaussian Elimination (with pivoting) to Linear Least Squares when the condition number of the matrix is larger than roughly 10^8. This switch is annoying for matrices which condition number are between 10^8 and 10^16, where the Gaussian Elimination can produce a more accurate result than Least Squares. The linalg_gesv function provided in this module is a direct interface to the Gaussian Elimination from Lapack. In some cases, this function can produce significantly more accurate solution than backslash. See the example below for the Hilbert matrix of size 8.

Examples

// A real system of equations
A=  [
1 2
3 4
];
e = [5,1,2,3;6,2,3,4];
b = [17,5,8,11;39,11,18,25];
x = linalg_gesv(A,b)
// A mixed system
A=  [
1 2
3 4
] + %i* [
5 6
7 8];
e = [5;6];
b = [17;39] + %i * [61;83];
x = linalg_gesv(A,b)

// Compare with Scilab for difficult matrix
n = 8;
e = ones(n,1);
A = testmatrix("hilb",n);
b = A*e;
// With backslash
x = A\b;
norm(A*x-b)/norm(b)
norm(x-e)/norm(e)
// With gesv
x = linalg_gesv(A,b);
norm(A*x-b)/norm(b)
norm(x-e)/norm(e)

Authors


Report an issue
<< linalg_gemm blaslapack linalg_zgemm >>