diff --git a/Cargo.toml b/Cargo.toml index 11c1b92..76cd9d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ toml = "0.4" url = "1.6" walkdir = "2.0" ansi_term = "0.11.0" +nalgebra = "0.16.12" [target.'cfg(target_os = "linux")'.dependencies] syslog = "4.0" diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 9707d08..116d55d 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -193,6 +193,7 @@ NaiveDate NaiveDateTime NaiveTime ndarray +nalgebra nFun NotFound NulError diff --git a/src/links.md b/src/links.md index dcce4f3..ba9de63 100644 --- a/src/links.md +++ b/src/links.md @@ -92,6 +92,8 @@ Keep lines sorted. [memmap]: https://docs.rs/memmap/ [mime-badge]: https://badge-cache.kominick.com/crates/v/csv.svg?label=mime [mime]: https://docs.rs/mime/ +[nalgebra-badge]: https://badge-cache.kominick.com/crate/nalgebra.svg?label=nalgebra +[nalgebra]: https://docs.rs/nalgebra [ndarray-badge]: https://badge-cache.kominick.com/crate/ndarray.svg?label=ndarray [ndarray]: https://docs.rs/ndarray [num-badge]: https://badge-cache.kominick.com/crates/v/num.svg?label=num diff --git a/src/science/mathematics.md b/src/science/mathematics.md index 1bf3318..6924c82 100644 --- a/src/science/mathematics.md +++ b/src/science/mathematics.md @@ -7,6 +7,7 @@ | [Adding matrices][add-matrices] | [![ndarray-badge]][ndarray] | [![cat-science-badge]][cat-science] | | [Multiplying matrices][multiply-matrices] | [![ndarray-badge]][ndarray] | [![cat-science-badge]][cat-science] | | [Multiply a scalar with a vector with a matrix][multiply-scalar-vector-matrix] | [![ndarray-badge]][ndarray] | [![cat-science-badge]][cat-science] | +| [Invert marix][invert-matrix] | [![nalgebra-badge]][nalgebra] | [![cat-science-badge]][cat-science] | | [Calculating the side length of a triangle][side-length] | [![std-badge]][std] | [![cat-science-badge]][cat-science] | | [Verifying tan is equal to sin divided by cos][tan-sin-cos] | [![std-badge]][std] | [![cat-science-badge]][cat-science] | | [Distance between two points on the Earth][latitude-longitude] | [![std-badge]][std] | [![cat-science-badge]][cat-science] | @@ -22,6 +23,7 @@ [add-matrices]: science/mathematics/linear_algebra.html#adding-matrices [multiply-matrices]: science/mathematics/linear_algebra.html#multiplying-matrices [multiply-scalar-vector-matrix]: science/mathematics/linear_algebra.html#multiply-a-scalar-with-a-vector-with-a-matrix +[invert-matrix]: science/mathematics/linear_algebra.html#invert-matrix [side-length]: science/mathematics/trigonometry.html#calculating-the-side-length-of-a-triangle [tan-sin-cos]: science/mathematics/trigonometry.html#verifying-tan-is-equal-to-sin-divided-by-cos [latitude-longitude]: science/mathematics/trigonometry.html#distance-between-two-points-on-the-earth diff --git a/src/science/mathematics/linear_algebra.md b/src/science/mathematics/linear_algebra.md index d27b5c6..f6e4644 100644 --- a/src/science/mathematics/linear_algebra.md +++ b/src/science/mathematics/linear_algebra.md @@ -5,5 +5,6 @@ {{#include linear_algebra/add-matrices.md}} {{#include linear_algebra/multiply-matrices.md}} {{#include linear_algebra/multiply-scalar-vector-matrix.md}} +{{#include linear_algebra/invert-matrix.md}} {{#include ../../links.md}} diff --git a/src/science/mathematics/linear_algebra/invert-matrix.md b/src/science/mathematics/linear_algebra/invert-matrix.md new file mode 100644 index 0000000..96f6cf5 --- /dev/null +++ b/src/science/mathematics/linear_algebra/invert-matrix.md @@ -0,0 +1,25 @@ +## Invert matrix +[![nalgebra-badge]][nalgebra] [![cat-science-badge]][cat-science] + +Creates a 3x3 matrix with [`nalgebra::Matrix3`] and inverts it, if possible. + +```rust +extern crate nalgebra; + +use nalgebra::Matrix3; + +fn main() { + let m1 = Matrix3::new(2.0, 1.0, 1.0, 3.0, 2.0, 1.0, 2.0, 1.0, 2.0); + println!("m1 = {}", m1); + match m1.try_inverse() { + Some(inv) => { + println!("The inverse of m1 is: {}", inv); + } + None => { + println!("m1 is not invertible!"); + } + } +} +``` + +[`nalgebra::Matrix3`]: https://docs.rs/nalgebra/*/nalgebra/base/type.Matrix3.html