[][src]Trait peroxide::structure::matrix::LinearAlgebra

pub trait LinearAlgebra {
    pub fn back_subs(&self, b: &Vec<f64>) -> Vec<f64>;
pub fn forward_subs(&self, b: &Vec<f64>) -> Vec<f64>;
pub fn lu(&self) -> PQLU;
pub fn waz(&self, d_form: Form) -> Option<WAZD>;
pub fn qr(&self) -> QR;
pub fn svd(&self) -> SVD;
pub fn rref(&self) -> Matrix;
pub fn det(&self) -> f64;
pub fn block(&self) -> (Matrix, Matrix, Matrix, Matrix);
pub fn inv(&self) -> Matrix;
pub fn pseudo_inv(&self) -> Matrix;
pub fn solve(&self, b: &Vec<f64>, sk: SolveKind) -> Vec<f64>;
pub fn solve_mat(&self, m: &Matrix, sk: SolveKind) -> Matrix; }

Linear algebra trait

Required methods

pub fn back_subs(&self, b: &Vec<f64>) -> Vec<f64>[src]

pub fn forward_subs(&self, b: &Vec<f64>) -> Vec<f64>[src]

pub fn lu(&self) -> PQLU[src]

pub fn waz(&self, d_form: Form) -> Option<WAZD>[src]

pub fn qr(&self) -> QR[src]

pub fn svd(&self) -> SVD[src]

pub fn rref(&self) -> Matrix[src]

pub fn det(&self) -> f64[src]

pub fn block(&self) -> (Matrix, Matrix, Matrix, Matrix)[src]

pub fn inv(&self) -> Matrix[src]

pub fn pseudo_inv(&self) -> Matrix[src]

pub fn solve(&self, b: &Vec<f64>, sk: SolveKind) -> Vec<f64>[src]

pub fn solve_mat(&self, m: &Matrix, sk: SolveKind) -> Matrix[src]

Loading content...

Implementors

impl LinearAlgebra for Matrix[src]

pub fn back_subs(&self, b: &Vec<f64>) -> Vec<f64>[src]

Backward Substitution for Upper Triangular

pub fn forward_subs(&self, b: &Vec<f64>) -> Vec<f64>[src]

Forward substitution for Lower Triangular

pub fn lu(&self) -> PQLU[src]

LU Decomposition Implements (Complete Pivot)

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

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix(vec![1,2,3,4], 2, 2, Row);
    let pqlu = a.lu();
    let (p,q,l,u) = (pqlu.p, pqlu.q, pqlu.l, pqlu.u);
    assert_eq!(p, vec![1]); // swap 0 & 1 (Row)
    assert_eq!(q, vec![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));
}

pub fn qr(&self) -> QR[src]

QR Decomposition

Translation of RosettaCode#Python

Example

extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("12 -51 4;6 167 -68; -4 24 -41");
    let qr = a.qr();
    let r = ml_matrix("-14 -21 14; 0 -175 70; 0 0 -35");
    #[cfg(feature="O3")]
    {
        assert_eq!(r, qr.r);
    }
    qr.r.print();
}

pub fn svd(&self) -> SVD[src]

Singular Value Decomposition

Examples

extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = ml_matrix("3 2 2;2 3 -2");
    #[cfg(feature="O3")]
    {
        let svd = a.svd();
        assert!(eq_vec(&vec![5f64, 3f64], &svd.s, 1e-7));
    }
    a.print();
}

pub fn rref(&self) -> Matrix[src]

Reduced Row Echelon Form

Implementation of RosettaCode

pub fn det(&self) -> f64[src]

Determinant

Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a.det(), -2f64);
}

pub fn block(&self) -> (Self, Self, Self, Self)[src]

Block Partition

Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    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));
}

pub fn inv(&self) -> Self[src]

Inverse of Matrix

Caution

inv function returns Option<Matrix> Thus, you should use pattern matching or unwrap to obtain inverse.

Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    // Non-singular
    let a = matrix!(1;4;1, 2, 2, Row);
    assert_eq!(a.inv(), matrix(c!(-2,1,1.5,-0.5),2,2,Row));

    // Singular
    //let b = matrix!(1;9;1, 3, 3, Row);
    //let c = b.inv(); // Can compile but..
    //let d = b.det();
    //assert_eq!(d, 0f64);
}

pub fn pseudo_inv(&self) -> Self[src]

Moore-Penrose Pseudo inverse

Description

$X^\dagger = (X^T X)^{-1} X^T$

Examples

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = matrix!(1;4;1, 2, 2, Row);
    let inv_a = a.inv();
    let pse_a = a.pseudo_inv();

    assert_eq!(inv_a, pse_a); // Nearly equal
}

pub fn solve(&self, b: &Vec<f64>, sk: SolveKind) -> Vec<f64>[src]

Solve with Vector

Solve options

  • LU: Gaussian elimination with Complete pivoting LU (GECP)
  • WAZ: Solve with WAZ decomposition

Reference

  • Biswa Nath Datta, Numerical Linear Algebra and Applications, Second Edition
  • Ke Chen, Matrix Preconditioning Techniques and Applications, Cambridge Monographs on Applied and Computational Mathematics

impl LinearAlgebra for SPMatrix[src]

Linear algebra for sparse matrix

Caution : In every ops in this trait, there is converting process to dense matrix

Loading content...