add(&self, other: Vec<f64>) -> Vec<f64>
sub(&self, other: Vec<f64>) -> Vec<f64>
mul(&self, other: Vec<f64>) -> Vec<f64>
div(&self, other: Vec<f64>) -> Vec<f64>
dot(&self, other: Vec<f64>) -> f64
norm(&self) -> f64
fn main() {
let a = c!(1,2,3,4);
let b = c!(4,3,2,1);
a.add(&b).print();
a.sub(&b).print();
a.mul(&b).print();
a.div(&b).print();
a.dot(&b).print();
a.norm().print();
// [5, 5, 5, 5]
// [-3, -1, 1, 3]
// [4, 6, 6, 4]
// [0.25, 0.6667, 1.5, 4]
// 20
// 5.477225575051661 // sqrt(30)
}
pow(&self, usize) -> Vec<f64>
powf(&self, f64) -> Vec<f64>
sqrt(&self) -> Vec<f64>
fn main() {
let a = c!(1,2,3,4);
a.pow(2).print();
a.powf(0.5).print();
a.sqrt().print();
// [1, 4, 9, 16]
// [1, 1.4142, 1.7321, 2]
// [1, 1.4142, 1.7321, 2]
}
There are two concatenation operations.
There are two ways to convert vector to matrix.
to_matrix(&self) -> Matrix
: Vector to column matrix
transpose(&self) -> Matrix
: Vector to row matrix
fn main() {
let a = c!(1,2,3,4);
let m_col = matrix(c!(1,2,3,4), 4, 1, Col); // (4,1) Matrix
assert_eq!(a.to_matrix(), m_col);
let m_row = matrix(c!(1,2,3,4), 1, 4, Row); // (1,4) Matrix
assert_eq!(a.transpose(), m_row);
}