- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How to use the result of readRealMatrix
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;
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;
- sjoelund.se
- 1700 Posts
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.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How to use the result of readRealMatrix