Function russell_lab::add_matrices [−][src]
pub fn add_matrices(
c: &mut Matrix,
alpha: f64,
a: &Matrix,
beta: f64,
b: &Matrix
) -> Result<(), &'static str>
Expand description
Performs the addition of two matrices
c := α⋅a + β⋅b
Example
use russell_lab::*;
let a = Matrix::from(&[
[ 10.0, 20.0, 30.0, 40.0],
[-10.0, -20.0, -30.0, -40.0],
]);
let b = Matrix::from(&[
[ 2.0, 1.5, 1.0, 0.5],
[-2.0, -1.5, -1.0, -0.5],
]);
let mut c = Matrix::new(2, 4);
add_matrices(&mut c, 0.1, &a, 2.0, &b)?;
let correct = "┌ ┐\n\
│ 5 5 5 5 │\n\
│ -5 -5 -5 -5 │\n\
└ ┘";
assert_eq!(format!("{}", c), correct);