pub struct Matrix { /* private fields */ }
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn from_vector(rows: usize, cols: usize, values: Vec<f64>) -> Self
pub fn from_vector(rows: usize, cols: usize, values: Vec<f64>) -> Self
Returns a new Matrix given the rows, columns and all the data inside the matrix.
§Arguments
rows
- The amount of rows of the matrixcols
- The amount of columns of the matrixvalues
- The data that the Matrix is created from (needs to be an 1D Vector)
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 2.0,
3.0, 4.0
];
let matrix = Matrix::from_vector(2, 2, vector);
Sourcepub fn get(&self, row: usize, col: usize) -> f64
pub fn get(&self, row: usize, col: usize) -> f64
Returns the data given the coordinates (row and column)
§Arguments
row
- The row where the data is locatedcol
- The column where the data is located
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 2.0,
3.0, 4.0
];
let matrix = Matrix::from_vector(2, 2, vector);
matrix.get(0, 0);
§Returns
The value on that coordinate
Sourcepub fn set(&mut self, row: usize, col: usize, value: f64)
pub fn set(&mut self, row: usize, col: usize, value: f64)
Sets a value given the coordinates (row and column) and the value
§Arguments
row
- The row where the data is locatedcol
- The column where the data is locatedvalue
- The value that is being set.
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 2.0,
3.0, 4.0
];
let mut matrix = Matrix::from_vector(2, 2, vector);
matrix.set(0, 0, 1.5);
Sourcepub fn is_squared(&self) -> bool
pub fn is_squared(&self) -> bool
Sourcepub fn main_diagonal(&self) -> (Vec<f64>, Vec<f64>, Vec<f64>)
pub fn main_diagonal(&self) -> (Vec<f64>, Vec<f64>, Vec<f64>)
Returns the main diagonal, all items above and below the main diagonal of a Matrix (only if it’s squared)
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 2.0,
3.0, 4.0
];
let matrix = Matrix::from_vector(2, 2, vector);
let (main_diagonal, above_diagonal, below_diagonal) = matrix.main_diagonal();
§Returns
The main diagonal, all numbers above the main diagoan and all numbers below the main diagonal. All diagonals are Vec
Sourcepub fn is_u_triangular(&self) -> bool
pub fn is_u_triangular(&self) -> bool
Returns if the matrix is upper triangular (e.g the matrix is squared and all numbers below the main diagonal are zero)
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 2.0,
0.0, 4.0
];
let matrix = Matrix::from_vector(2, 2, vector);
matrix.is_u_triangular(); // Should return true
§Returns
A boolean based on the result.
Sourcepub fn is_l_triangular(&self) -> bool
pub fn is_l_triangular(&self) -> bool
Returns if the matrix is lower triangular (e.g the matrix is squared and all numbers above the main diagonal are zero)
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 0.0,
1.0, 4.0
];
let matrix = Matrix::from_vector(2, 2, vector);
matrix.is_l_triangular(); // Should return true
§Returns
A boolean based on the result.
Sourcepub fn concat_rows(&self, other: &Self) -> Self
pub fn concat_rows(&self, other: &Self) -> Self
Returns a new Matrix when given two matrices and both matrices have the same number of rows, join all rows
§Arguments
other
- The matrix that is concatenating all rows.
§Examples
use tinymatrix::Matrix;
let vector1 = vec![
1.0, 2.0,
3.0, 4.0
];
let vector2 = vec![
5.0, 6.0,
7.0, 8.0
];
let matrix1 = Matrix::from_vector(2, 2, vector1);
let matrix2 = Matrix::from_vector(2, 2, vector2);
let joined_rows = matrix1.concat_rows(&matrix2);
§Returns
A new matrix with all rows joint.
Sourcepub fn concat_cols(&self, other: &Self) -> Self
pub fn concat_cols(&self, other: &Self) -> Self
Returns a new Matrix when given two matrices and they have the same amount of columns, join all columns
§Arguments
other
- The matrix that is concatenating all columns.
§Examples
use tinymatrix::Matrix;
let vector1 = vec![
1.0, 2.0,
3.0, 4.0
];
let vector2 = vec![
5.0, 6.0,
7.0, 8.0
];
let matrix1 = Matrix::from_vector(2, 2, vector1);
let matrix2 = Matrix::from_vector(2, 2, vector2);
let joined_rows = matrix1.concat_cols(&matrix2);
§Returns
A new matrix with all columns joint.
pub fn transpose(&self) -> Self
pub fn determinant(&self) -> Self
pub fn lu_decomposition(&self) -> Self
Sourcepub fn print_matrix(&self)
pub fn print_matrix(&self)
Prints the matrix in a nice way. Useful for debugging.
§Examples
use tinymatrix::Matrix;
let vector = vec![
1.0, 2.0,
3.0, 4.0
];
let matrix = Matrix::from_vector(2, 2, vector);
matrix.print_matrix();