Is it possible to compute complex matrix expressions from real matrices with nalgebra?

64 Views Asked by At

I have a bunch of real matrices and some complex scalar values. From those I would like to compute complex matrices, mainly by multiplying the matrices with those complex scalars as well as adding/subtracting real and complex matrices. In the end I would like to get a real matrix back by extracting the real part of the complex result.

For the first part I considered using the scale() function, but it only seems to support real scale factors when called on a real matrix. That would probably be easier if I started with complex matrices in the first place, but I would like to avoid that if possible. For the second part I have no ideas, except to collect the result into a new matrix myself component-wise.

Here is an illustrative example of what I actually want to compute:

use nalgebra::{DMatrix, DVector, Complex};

fn main() {
    let n = 10;
    let i = Complex::i();
    let w = 1.0;
    let t = 0.1;


    let I = DMatrix::<f64>::identity(n, n);
    let A = DMatrix::<f64>::new_random(n, n);
    let P = DMatrix::<f64>::new_random(n, n);
    let b = DVector::<f64>::new_random(n);

    // What I want to compute (pseudocode)

    let T = (I - 1.0/(w*i)*A).lu();
    let x = (1.0/(w*i) * T.solve(I*(i*w*t).exp() - P)*b).real();
}
0

There are 0 best solutions below