Inverse of Dynamic Matrix

I need to get the inverse of a matrix but I don’t know the dimensions of it at compile time. The only thing I do know is that it will be a square matrix and will have a non-zero determinate.

The functions try_inverse and inverse work on stack allocated matrices like Matrix4, but they don’t seem to be implemented for dynamically allocated types like MatrixVec. Is there something I’m missing? Like a trait I need to import or maybe I’m using the wrong type? Any help would be greatly appreciated.

Using the matrix.try_inverse() method instead of the function at the crate root should work. There are several functions at the crate root that I will deprecate sinte they work only on statically-sized matrices.

@sebcrozet I did do matrix.try_inverse(), sorry I should have specified. Here’s the code:

use nalgebra::MatrixVec;

let elements = vec![...]; // has n x n elements
let mat = MatrixVec::new(Dynamic::new(n), Dynamic::new(n), elements);

if let Some(inv) = mat.try_inverse() {
    // use inv

I get the error:

error[E0599]: no method named `try_inverse` found for type `nalgebra::MatrixVec<f64, nalgebra::Dynamic, nalgebra::Dynamic>` in the current scope

I originally assumed I just needed to import some trait, but after looking through the documentation I couldn’t find anything. If it helps I’m using version 0.15.3 which I believe is the latest.

I didn’t realize you were using MatrixVec. This is a type of a matrix data storage, i.e., one of the possible types for the S type parameter of the abstract Matrix type (see this). For a dynamically-sized matrix, you should use the DMatrix type alias instead.