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

complex arrays in OpenModelica

complex arrays in OpenModelica

hi,


   can anyone help me

How to define complex numbers in arrays in openmodelcia, does the complex number take two boxes in the array or one



 

Re: complex arrays in OpenModelica

Learn Modelica please:
https://mbe.modelica.university/

Complex is part of the MSL.
https://github.com/modelica/ModelicaSta … Complex.mo

Code:


Complex c[10];
// c[1] is the complex
// c[1].im is the im part
// c[1].re is the real part

Re: complex arrays in OpenModelica

hi,


   thank you for your answer;


  in fact, I have a variable in my function and during simulation can takes real and complex numbers, so my question is how can I define this variable in the top of the function


thanks in advance

Re: complex arrays in OpenModelica

Hi,

In Modelica you need to define the type of the variables. If your variable can take complex values it is a Complex, in the same way a variable than can get integer and fractional values is a Real, not an Integer.
Of course you can't do real operations using complex numbers, but I understand that you can always define a Real and make it equal to the real part of your complex number, and play later with this real. Or use directly the real part of your complex number in the needed operations.

Re: complex arrays in OpenModelica

CTG,

thank you CTG for your answer.

I do what you told me to do, but, now I have another problem in derivative of complex function.

is there a function which allow us to derivate a complex function? else you can give me an idea how to do this

can you help me, please?

thank you in advance for your answer

Code:




der(T2[i]) =(q_cd_g_pv * (T1[i] - T2[i]) - q_cd_pv_ted * (T2[i] - T3[i]) + (tau_fg * alfa_pv - eta) * G[i] * Apv + tau_fg * alfa_eva * G[i] * (Ag - Apv)) * (1 / Cpv);

message error: [OM_Modello3_11: 340:5-340:207]: Type mismatch for positional argument 1 in der(=T1[i]). The argument has type:
  Complex
expected type:
  Real

Re: complex arrays in OpenModelica

Well, I told you not to do reals operations with complex numbers. As stated in Modelica 3.4 specification (3.7.2), the time derivative operator der() works on reals and reals arrays, giving as output a real or a real array. A possible workaround can be something like this:

model ComplexDerivative
  Complex c;
  Real r[2](start={2,2});
equation
  r[1]=c.re;
  r[2]=c.im;
  der(r)={2,3};
end ComplexDerivative;

Where the start and derivative values can be a more sophisticated expression.


Re: complex arrays in OpenModelica

CTG,
 
   thank you,   I take what you told me with your example and I will apply it in my model.

Re: complex arrays in OpenModelica

GTC

thank you it works very well;

I try to translate a program of temperature variation from Matlab to OpenModelica, so in matlab, the initial conditions are updated for each iteration, like shown in the code below,

How I can do that in OpenModelica?

Code:




T0_7=[16.2+273.15 16.2+273.15 16.2+273.15 16.2+273.15  16.2+273.15 16.2+273.15  32+273.15 ];


t0=0;                %Istante di tempo iniziale
tf=60;              %Istante di tempo finale
tspan=t0:1:t0+tf-1;  %Intervallo di tempo


Tint=16.2; %celsus
Tint=Tint+273.15;% kelvin

N_misure=1440;% nobre de mesure
TT_7=zeros((tf*N_misure),7);

for i=1:1:N_misure
   
   
    options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-4 1e-4 1e-4 1e-4 1e-4 ]);
   
    %Risoluzione del modello (8) modificato tramite il metodo Runge Kutta del 4 ordine

    [t_7,T_7]=ode45('Modello3',tspan,T0_7,options);         
    T_7=real(T_7);
   

    T0_7=T_7(length(T_7),:)



Edited by: Abderezakabidi - May-11-20 01:10:33
There are 0 guests and 0 other users also viewing this topic
You are here: