Search code examples
interpolationcurve-fittingmodelicaopenmodelica

Function to Interpolate using openmodelica


I have some data extracted from matlab which i want them to be accessible in openmodelica. The data are in the form of table of x,y and the value z. I want to create a function the reproduce the point z out of x and y, in which the function can also interpolates nicely between x and y. So basically the Modelica interpolation will have to load the table of results and do the interpolation. Is this possible ? can anyone lead me to the way ? thanks for the help in advance.

I attached my data with this message, the first row and the first column corresponds to the x and y values respectively.

https://www.dropbox.com/s/75z2ejcjru8hiu8/data.zip?dl=0


Solution

  • You need to adapt the data file according to https://doc.modelica.org/Modelica%203.2.3/Resources/helpOM/Modelica.Blocks.Tables.CombiTable2D.html, i.e., do not leave the element at position (0,0) empty. See https://gist.github.com/tbeu/2004db0f7753e69f42da39aec3a00b3d for the fix.

    Then, you can load and interpolate the data using MSL v3.2.3, for example

    model Model
      Modelica.Blocks.Tables.CombiTable2D combiTable2D(
        tableOnFile=true,
        tableName="A'_Coefficient",
        fileName="c:\\temp\\data.txt") annotation(Placement(transformation(extent={{-95,60},{-75,80}})));
      Modelica.Blocks.Sources.RealExpression realExpression1(y=time*10) annotation(Placement(transformation(extent={{-140,65},{-120,85}})));
      Modelica.Blocks.Sources.RealExpression realExpression2(y=time*100) annotation(Placement(transformation(extent={{-140,40},{-120,60}})));
      equation
        connect(realExpression1.y,combiTable2D.u1) annotation(Line(points={{-119,75},{-114,75},{-102,75},{-102,76},{-97,76}}, color={0,0,127}));
        connect(realExpression2.y,combiTable2D.u2) annotation(Line(points={{-119,50},{-114,50},{-102,50},{-102,64},{-97,64}}, color={0,0,127}));
      annotation(uses(Modelica(version="3.2.3")));
    end Model;