[−][src]Trait peroxide::structure::matrix::LinearAlgebra
Linear algebra trait
Required methods
fn norm(&self, norm: Norm) -> f64
fn lu(&self) -> Option<PQLU>
fn det(&self) -> f64
fn block(&self) -> (Matrix, Matrix, Matrix, Matrix)
fn inv(&self) -> Option<Matrix>
fn pseudo_inv(&self) -> Option<Matrix>
Implementors
impl LinearAlgebra for Matrix
[src]
fn norm(&self, norm: Norm) -> f64
[src]
Matrix norm
Kinds
Frobenius
: Frobenius normPQ(usize, usize)
: L_pq normOne
: 1-normInfinity
: Infinity norm
fn lu(&self) -> Option<PQLU>
[src]
LU Decomposition Implements
Description
It use complete pivoting LU decomposition. You can get two permutations, and LU matrices.
Caution
It returns Option<PQLU>
- You should unwrap to obtain real value.
PQLU
has four field - p
, q
, l
, u
.
p
, q
are permutations.
l
, u
are matrices.
Examples
extern crate peroxide; use peroxide::*; let a = matrix(vec![1,2,3,4], 2, 2, Row); let pqlu = a.lu().unwrap(); let (p,q,l,u) = (pqlu.p, pqlu.q, pqlu.l, pqlu.u); assert_eq!(p, vec![(0,1)]); // swap 0 & 1 (Row) assert_eq!(q, vec![(0,1)]); // swap 0 & 1 (Col) assert_eq!(l, matrix(c!(1,0,0.5,1),2,2,Row)); assert_eq!(u, matrix(c!(4,3,0,-0.5),2,2,Row));
fn det(&self) -> f64
[src]
Determinant
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.det(), -2f64);
fn block(&self) -> (Self, Self, Self, Self)
[src]
Block Partition
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;16;1, 4, 4, Row); let (m1, m2, m3, m4) = a.block(); assert_eq!(m1, matrix(c!(1,2,5,6), 2, 2, Row)); assert_eq!(m2, matrix(c!(3,4,7,8), 2, 2, Row)); assert_eq!(m3, matrix(c!(9,10,13,14), 2, 2, Row)); assert_eq!(m4, matrix(c!(11,12,15,16), 2, 2, Row)); let b = matrix!(1;16;1, 4, 4, Col); let (m1, m2, m3, m4) = b.block(); assert_eq!(m1, matrix(c!(1,2,5,6), 2, 2, Col)); assert_eq!(m3, matrix(c!(3,4,7,8), 2, 2, Col)); assert_eq!(m2, matrix(c!(9,10,13,14), 2, 2, Col)); assert_eq!(m4, matrix(c!(11,12,15,16), 2, 2, Col));
fn inv(&self) -> Option<Self>
[src]
Inverse of Matrix
Caution
inv
function returns Option<Matrix>
Thus, you should use pattern matching or unwrap
to obtain inverse.
Examples
extern crate peroxide; use peroxide::*; // Non-singular let a = matrix!(1;4;1, 2, 2, Row); assert_eq!(a.inv().unwrap(), matrix(c!(-2,1,1.5,-0.5),2,2,Row)); // Singular let b = matrix!(1;9;1, 3, 3, Row); assert_eq!(b.inv(), None);
fn pseudo_inv(&self) -> Option<Self>
[src]
Moore-Penrose Pseudo inverse
Description
(X^T X)^{-1} X
Examples
extern crate peroxide; use peroxide::*; let a = matrix!(1;4;1, 2, 2, Row); let inv_a = a.inv().unwrap(); let pse_a = a.pseudo_inv().unwrap(); assert_eq!(inv_a, pse_a); // Nearly equal