Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Problem calling functions with matrixes of complex numbers

Problem calling functions with matrixes of complex numbers

Hi everyone,

I have to make functions dealing with matrixes of complex numbers. For instance, I would like to make a function returning, as its output, the real part of a matrix of complexes given in input.

I manage to compile the following code, which does the job:

Code:

encapsulated class testRealMatrix2

import Modelica.ComplexMath.real;
import Complex;

Complex A[2,2] = [Complex(1,1),Complex(2,3);
                  Complex(2,2), Complex(6,1)];
Real A_Re[2,2];

algorithm
for i in 1:size(A,1) loop
  for k in 1:size(A,2) loop
  A_Re[i,k] := real(A[i,k]);
  end for;
end for;
                   
end testRealMatrix2;

But when I try to make it as a function, I have troubles to compile (see image below):

Code:


encapsulated class testRealMatrix1
import Modelica.ComplexMath.real;
import Complex;

function realMatrix
input Complex A[2,2];
output Real A_Re[2,2];

algorithm
for i in 1:size(A,1) loop
  for k in 1:size(A,2) loop
  A_Re[i,k] := real(A[i,k]);
  end for;
end for;
end realMatrix;

Complex A[2,2] = [Complex(1,1),Complex(2,3);
                  Complex(2,2), Complex(6,1)];
Real A_Re[2,2];

algorithm
A_Re := realMatrix(A);
                   
end testRealMatrix1;

https://framapic.org/wETZBKGvpdiF/EzEbXGysarzj.PNG

It seems there is an incompatibility of type when traducing the Modelica program in C... But I don't really understand what is the problem and how I could solve it.
Oh, and by the way I also tried to call a function on matrixes of real, it works. It seems the problem only concerns matrixes of complexes.

Would anyone know what's wrong?

By advance, thank you

Re: Problem calling functions with matrixes of complex numbers

I forgot to mention that I also tested the "testRealMatrix1" on Dymola on which it worked. So I don't know what's wrong with OpenModelica and functions using Matrixes of complex numbers...

There are 0 guests and 0 other users also viewing this topic
You are here: