CogniPilot

MODELICA LIBRARY · ENGINEERING REFERENCE

function

Polynomials.derivativeCostMatrix

Integral quadratic cost matrix for a polynomial derivative

Public declarations

Explicit source declarations; dimensions, modifications and defaults are shown as written, without evaluation.

RoleNameTypeDimensions / attributes / defaultDescription
inputcoefficientCountInteger(min=1)
inputderivativeOrderInteger(min=0)
inputintervalLengthReal(min=0.0)
outputcostReal[coefficientCount, coefficientCount]

Modelica declarations and implementation

Show parameters, interfaces and source

Parameters, inputs, outputs, defaults and equations from the source file.

function derivativeCostMatrix
  "Integral quadratic cost matrix for a polynomial derivative"
  input Integer coefficientCount(min=1);
  input Integer derivativeOrder(min=0);
  input Real intervalLength(min=0.0);
  output Real cost[coefficientCount, coefficientCount];
protected
  Integer leftPower;
  Integer rightPower;
  Integer exponent;
algorithm
  cost := zeros(coefficientCount, coefficientCount);
  for row in 1:coefficientCount loop
    leftPower := row - 1;
    for column in 1:coefficientCount loop
      rightPower := column - 1;
      if leftPower >= derivativeOrder and rightPower >= derivativeOrder then
        exponent := leftPower + rightPower - 2 * derivativeOrder + 1;
        cost[row, column] :=
          Polynomials.fallingFactorial(leftPower, derivativeOrder)
          * Polynomials.fallingFactorial(rightPower, derivativeOrder)
          * intervalLength^exponent / exponent;
      end if;
    end for;
  end for;
end derivativeCostMatrix;