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

Array in modelica language

Array in modelica language

Hi,

Can someone please tell me how to declare an array in modelica? What is the syntax for it? kindly give an example.

Thanks

Re: Array in modelica language

Code:

Real r[3]; // Real array, 1 dimension of size 3

Re: Array in modelica language

okay thanks .. and if i need to put the 3 values then should i use the following syntax??

Real r[3] =[1.1, 2.1, 3.1];

Re: Array in modelica language

That is matrix syntax (2-dimensional). 1D-arrays use curly bracers:
Real r[3] ={1.1, 2.1, 3.1};

Re: Array in modelica language

thanks a lot current/smile

Re: Array in modelica language

Can you also please tell me about matrix.. what is the proper syntax for declaring a matrix with 2 rows and 3 columns .. and values in first row being 1,2,3 and second row 4,5,6 ?

Re: Array in modelica language

Code:

>>> loadString("model M Real r[2,3] = [1,2,3;4,5,6]; end M;")

true
>>> instantiateModel(M)
"class M
  Real r[1,1];
  Real r[1,2];
  Real r[1,3];
  Real r[2,1];
  Real r[2,2];
  Real r[2,3];
equation
  r = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}};
end M;
"

As you can see, it is also possible to nest the array constructor to create a matrix.

Re: Array in modelica language

Hi,

I suggest you read these things:
Modelica specification (Chapter 10 is about arrays):
https://modelica.org/documents/ModelicaSpec33.pdf

Some more stuff about Modelica:
https://www.openmodelica.org/images/doc … torial.pdf
Some OpenModelica documentation:
https://www.openmodelica.org/index.php/ … umentation

Cheers,
Adrian Pop/

Re: Array in modelica language

hi,

    can you please show me how to declare a matrix with (n lines and j columns) and how extract a specific column

Code:


Matrix=[1 2 5;4 5 3;1 9 8]

a=Matrix(2,:)

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