Search code examples
modelica

Modelica Cubic hermite interpolation


I have a question regarding CubicHermite function from the Modelica Standard Library (Modelica.Fluid.Utilities.cubicHermite).

I have the following inputs to the function. input Real x "Abscissa value";

  input Real x1 "Lower abscissa value";
  input Real x2 "Upper abscissa value";
  input Real y1 "Lower ordinate value";
  input Real y2 "Upper ordinate value";
  input Real y1d "Lower gradient";
  input Real y2d "Upper gradient";
  output Real y "Interpolated ordinate value";

I'm a bit confused, how to calculate the y1d and y2d values?


Solution

  • As I understand your question, you are asking how to calculate the derivatives y1d (derivative at the point y1) and y2d (the derivative at the point y2). The short answer is however you would like (e.g., simple slopes: (y(i+1)-y(i))/(x(i+1)-x(i))). Just make sure your choice is appropriate for the case.

    Though to be, perhaps, a bit more helpful I would recommend taking a look at the implementation of the CubicHermite function in the Buildings Library here.

    The derivative is calculated is the function call to "splineDerivatives" for which the code can be found on Github here.

    splineDerivatives appears to also have the helpful case of taking into account derivatives on the edge of the data set as well as within the data set.

    Update:

    I found a Mathworks pdf here that describes their use of cubic hermite spline and two methods they use called "pchip" (Section 3.4) and "spline" (Section 3.5).