Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.28 KB

README.md

File metadata and controls

53 lines (39 loc) · 1.28 KB

mathematica

A bunch of useful mathematical functions and operations, in rust!!

for now there's only vectors & matrices

step by step for newbies:

cargo new <anyname> --bin

now open <anyname/src> in Cargo.toml add:

[dependecies]
mathematica = { git = "https://github.com/BilakshanP/mathematica" }

now u may use the following code in main.rs:

use mathematica::vectors::Vector as v;
use mathematica::matrices::Matrix as m;

fn main() {
    let vector_1 = v::new(1.0, 2.0, 3.0);
    let vector_2 = v::new(5.0, 6.0, 9.0);

    println!("Vector 1: {}\nVector 2: {}", vector_1, vector_2);
    println!("Vector/Cross product of Vector 1 & 2: {}", vector_1.cross(&vector_2));

    let matrix_1 = m::new_from_vec_sized(
        vec![
            1.0, 2.0, 3.0,
            4.0, 7.0, 8.0,
            2.0, 6.0, 4.0
        ], 3, 3).unwrap();
    let matrix_2 = m::new_identity_matrix(3).times(2.0);
    let matrix_3 = matrix_1.transpose().cross(&matrix_2).unwrap();

    println!("Matrix 1:\n{}\n", matrix_1);
    println!("Matrix 2:\n{}\n", matrix_2);

    println!(
        "Matrix/Cross product of Matrix 1's transpose and an Identity matrix of same size times 2:\n{}\n",
        matrix_3
    );

    println!("Determinant of above matrix is: {}", matrix_3.determinant());
}