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

How to use the result of readRealMatrix

How to use the result of readRealMatrix

I try to read a matrix with readRealMatrix and mutiply it by a vector x.

How can I create the vector x with dimension equal to those of the matrix :

model TestRead
  "Demonstrate usage of function Streams.readRealMatrix"
  import Modelica.Utilities.Streams.print;
  extends Modelica.Icons.Example;
   final parameter String file1 = Modelica.Utilities.Files.loadResource("modelica://Modelica/Resources/Data/Utilities/Test_RealMatrix_v4.mat") "File name of check matrix 1";

  final parameter String matrixName1 = "Matrix_A" "Names of check matrices";
  final parameter Integer dim1[2] = Modelica.Utilities.Streams.readMatrixSize(file1,matrixName1) "Dimension of check matrix 1";

  final parameter Real A1[:,:] = Modelica.Utilities.Streams.readRealMatrix(file1,matrixName1,dim1[1],dim1[2]) "Data of check matrix 1";

  Real x[dim1[1]] (each fixed = false)  "Dummy state" ;
  Real y ;
  initial equation
  x = fill(1.,dim1[1]) ;
equation

y  = -A1[1,1]*x[1];

end TestRead;

Edited by: JPG84 - Mar-23-21 09:45:45

Re: How to use the result of readRealMatrix

You can only have the vector on the left side of a multiplication (x*A1 is OK, A1*x is not). https://specification.modelica.org/main … ric-arrays

The following should work (I made y a vector)

Code:

model TestRead

  "Demonstrate usage of function Streams.readRealMatrix"
  import Modelica.Utilities.Streams.print;
  extends Modelica.Icons.Example;
   final parameter String file1 = Modelica.Utilities.Files.loadResource("modelica://Modelica/Resources/Data/Utilities/Test_RealMatrix_v4.mat") "File name of check matrix 1";

  final parameter String matrixName1 = "Matrix_A" "Names of check matrices";
  final parameter Integer dim1[2] = Modelica.Utilities.Streams.readMatrixSize(file1,matrixName1) "Dimension of check matrix 1";

  final parameter Real A1[:,:] = Modelica.Utilities.Streams.readRealMatrix(file1,matrixName1,dim1[1],dim1[2]) "Data of check matrix 1";

  Real x[dim1[1]] (each fixed = false)  "Dummy state" ;
  Real y[dim1[2]];
  initial equation
  x = fill(1.,dim1[1]) ;
equation

y  = -x*A1;

end TestRead;

Re: How to use the result of readRealMatrix

Thank you

In fact I should had been more specific : there is an error :

Could not evaluate structural parameter (or constant): dim1[1] which gives dimensions of array: x[dim1[1]]. Array dimensions must be known at compile time.

Re: How to use the result of readRealMatrix

Try using a more recent version of OpenModelica. 1.17.0 (to be released soon, I think contains the fixes for that) or the nightly builds should resolve that particular issue.

Edit: 1.17.0 (Windows) was uploaded yesterday: https://build.openmodelica.org/omc/buil … nal/64bit/ . Linux builds are still being compiled.

Edited by: sjoelund.se - Mar-23-21 10:38:11

Re: How to use the result of readRealMatrix

works fine in 1.17.0-dev beta3 and 1.18. dev 171
.
Thank you very much

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