On this page:
top
up

7.9Solving Systems of EquationsπŸ”— i

procedure

( matrix-solve MB[fail])(U F(Matrix Number ))

fail:(-> F)=(λ ()(error ... ))
Returns the matrix X for which (matrix* MX) is B. M and B must have the same number of rows.

It is typical for B (and thus X) to be a column matrix, but not required. If B is not a column matrix, matrix-solve solves for all the columns in B simultaneously.

Examples:
> (define M(matrix [[75][3-2]]))
> (define B0(col-matrix [322]))
> (define B1(col-matrix [194]))
> (matrix-solve MB0)

- : (Array Real)

(array #[#[4] #[-5]])

> (matrix* M(col-matrix [4-5]))

- : (Array Integer)

(array #[#[3] #[22]])

> (matrix-solve MB1)

- : (Array Real)

(array #[#[2] #[1]])

- : (Listof (Array Real))

(list (array #[#[4] #[-5]]) (array #[#[2] #[1]]))

matrix-solve does not solve overconstrained or underconstrained systems, meaning that M must be invertible. If M is not invertible, the result of applying the failure thunk fail is returned.

matrix-solve is implemented using matrix-gauss-elim to preserve exactness in its output, with partial pivoting for greater numerical stability when M is not exact.

See vandermonde-matrix for an example that uses matrix-solve to compute Legendre polynomials.

procedure

( matrix-inverse M[fail])(U F(Matrix Number ))

fail:(-> F)=(λ ()(error ... ))
Wikipedia: Invertible Matrix Returns the inverse of M if it exists; otherwise returns the result of applying the failure thunk fail.

Examples:

- : (Array Real)

(array #[#[1 0 0] #[0 1 0] #[0 0 1]])

> (matrix-inverse (matrix [[75][3-2]]))

- : (Array Real)

(array #[#[2/29 5/29] #[3/29 -7/29]])

> (matrix-inverse (matrix [[12][1020]]))

matrix-inverse: contract violation

expected: matrix-invertible?

given: (array #[#[1 2] #[10 20]])

> (matrix-inverse (matrix [[12][1020]])(λ ()#f))

- : (U (Array Real) False)

#f

procedure

( matrix-invertible? M)Boolean

Returns #t when M is a square-matrix? and (matrix-determinant M) is nonzero.

procedure

( matrix-determinant M)Number

Wikipedia: Determinant Returns the determinant of M, which must be a square-matrix? .

Examples:

- : Real

24

> (* 1234)

- : Integer [more precisely: Positive-Integer]

24

> (matrix-determinant (matrix [[12][1020]]))

- : Real

0

square-matrix-size: contract violation

expected: square-matrix?

given: (array #[#[1] #[2]])

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /