- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Complex matrix inversion

## Complex matrix inversion

### Complex matrix inversion

I have a problem that requires inversion of complex matrix: it is needed for the computation of complex impedances of a bundle of electric lines.

I see that MSL only supplies real matrix inversion "inv.mo" via lapack routines dgetrf() and dgetri().

I know that usage of inv() is discouraged, but in my problem is ok, since inversion is required only at system initialization.

I also know that lapack has twin functions cgetrf() and cgetri() for complex numbers, but I'n not sure whether that complex functions are included in the MSL's lapack dll (I suspect they are not).

Can anyone help me increating a "cinv.mo" function that does the same "inv.mo" does, but is for complex numbers?

Maibe this is not a trivial task since the MSL External Function Interface does not consider complex numbers.

Thanks.

**Edited by:**ceraolo - Aug-29-16 10:30:17

- ceraolo
- 147 Posts

### Re: Complex matrix inversion

I don't know the details of your problem, so I don't know what you need that inverse for. Assuming you really need to see the individual values of that matrix, I guess you can solve the problem by equations. Something along these lines

model ComplexInverse

constant Complex j = Complex(0,1);

Complex A[2,2] = {{1.0+0*j, 1.0+j}, {0.0 + 0*j, 1.0 + 0*j}};

Complex I[2,2];

Complex invA[2,2];

equation

I = identity(2)*Complex(1.0,0.0);

A*invA = I;

end ComplexInverse;

- casella
- 8 Posts

### Re: Complex matrix inversion

That's wonderful, Francesco.

Sometimes I forget that I'm playing with a very powerful programming language!

This helps a lot solving my problem.

In my original idea I had to invert a matrix inside a function, so inside an algorithm section; this in principle forbids the use of equations, and the technique you proposed.

But my function has to be called only at the beginning of the simulation, so I will try to mix the equation required for the inversion technique you suggested with equations using function calls, in an "when initial()" section.

**Edited by:**ceraolo - Sep-01-16 12:23:42

- ceraolo
- 147 Posts

### Re: Complex matrix inversion

Two further remarks

1. I would have liked to use parameters with fixed = false and initial equations, but due to some OMC bug this didn't work, so I used plain variables for my example.

2. Even if you do so, OMC will recognise that these variables are not time-varying, and move their computation to the initialization section automatically

- casella
- 8 Posts

- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Complex matrix inversion