mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
davhojt
2ea9e5a782
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
matrix
Instructions
Define a data structure to represent a matrix of any size and implement some basic operations.
We will consider a matrix as a rectangular arrangements of scalars. You can represent this as a 2 dimensional vector`. You will use the definition of scalars from the lalgebra_scalar exercise.
Implement the following associated functions:
new
: which returns a matrix of size1 x 1
.identity
: which returns the identity matrix of size n.zero
: which returns a matrix of sizerow
xcol
with all the positions filled by zeros.
Expected Functions and Structure
pub struct Matrix<T>(pub Vec<Vec<T>>);
impl <T: Scalar<Item = T>> Matrix<T> {
pub fn new() -> Matrix<T> {
}
pub fn zero(row: usize, col: usize) -> Matrix<T> {
}
pub fn identity(n: usize) -> Matrix<T> {
}
}
Usage
Here is a program to test your function.
use matrix::*;
fn main() {
let m: Matrix<u32> = Matrix(vec![vec![0, 0, 0, 0], vec![0, 0, 0, 0], vec![0, 0, 0, 0]]);
println!("{:?}", m);
println!("{:?}", Matrix::<i32>::identity(4));
println!("{:?}", Matrix::<f64>::zero(3, 4));
}
And its output:
$ cargo run
Matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
Matrix([[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]])
$