CombiTable1Dv

Table look-up in one dimension (matrix/file) with n inputs and n outputs

    CombiTable1Dv

Library

Modelica/Blocks/Tables

Description

Univariate constant, linear or cubic Hermitespline interpolation in one dimension of atable.Via parameter columns it can be defined how many columns of thetable are interpolated. If, e.g., columns={2,4}, it is assumed that 2 inputand 2 output signals are present and that the first output interpolatesthe first input via column 2 and the second output interpolates thesecond input via column 4 of the table matrix.

The grid points and function values are stored in a matrix "table[i,j]",where the first column "table[:,1]" contains the grid points and theother columns contain the data to be interpolated. Example:

table = [0,  0;         1,  1;         2,  4;         4, 16]If, e.g., the input u = 1.0, the output y =  1.0,    e.g., the input u = 1.5, the output y =  2.5,    e.g., the input u = 2.0, the output y =  4.0,    e.g., the input u =-1.0, the output y = -1.0 (i.e., extrapolation).
  • The interpolation interval is found by a binary search where the interval used in the last call is used as start interval.
  • Via parameter smoothness it is defined how the data is interpolated:
    smoothness = 1: Linear interpolation           = 2: Akima interpolation: Smooth interpolation by cubic Hermite                splines such that der(y) is continuous, also if extrapolated.           = 3: Constant segments           = 4: Fritsch-Butland interpolation: Smooth interpolation by cubic                Hermite splines such that y preserves the monotonicity and                der(y) is continuous, also if extrapolated.           = 5: Steffen interpolation: Smooth interpolation by cubic Hermite                splines such that y preserves the monotonicity and der(y)                is continuous, also if extrapolated.           = 6: Modified Akima interpolation: Smooth interpolation by cubic                Hermite splines such that der(y) is continuous, also if                extrapolated. Additionally, overshoots and edge cases of the                original Akima interpolation method are avoided.
  • First and second derivatives are provided, with exception of the following two smoothness options.
    1. No derivatives are provided for interpolation by constant segments.
    2. No second derivative is provided for linear interpolation.
  • Values outside of the table range, are computed by extrapolation according to the setting of parameter extrapolation:
    extrapolation = 1: Hold the first or last value of the table,                   if outside of the table scope.              = 2: Extrapolate by using the derivative at the first/last table                   points if outside of the table scope.                   (If smoothness is LinearSegments or ConstantSegments                   this means to extrapolate linearly through the first/last                   two table points.).              = 3: Periodically repeat the table data (periodical function).              = 4: No extrapolation, i.e. extrapolation triggers an error
  • If the table has only one row, the table value is returned, independent of the value of the input signal.
  • The grid values (first column) have to be strictly increasing.

The table matrix can be defined in the following ways:

  1. Explicitly supplied as parameter matrix "table", and the other parameters have the following values:
    tableName is "NoName" or has only blanks,fileName  is "NoName" or has only blanks.
  2. Read from a file "fileName" where the matrix is stored as "tableName". Both text and MATLAB MAT-file format is possible. (The text format is described below). The MAT-file format comes in four different versions: v4, v6, v7 and v7.3. The library supports at least v4, v6 and v7 whereas v7.3 is optional. It is most convenient to generate the MAT-file from FreeMat or MATLAB® by command
    save tables.mat tab1 tab2 tab3
    or Scilab by command
    savematfile tables.mat tab1 tab2 tab3
    when the three tables tab1, tab2, tab3 should be used from the model.
    Note, a fileName can be defined as URI by using the helper function loadResource.
  3. Statically stored in function "usertab" in file "usertab.c". The matrix is identified by "tableName". Parameter fileName = "NoName" or has only blanks. Row-wise storage is always to be preferred as otherwise the table is reallocated and transposed. See the Tables package documentation for more details.

When the constant "NO_FILE_SYSTEM" is defined, all file I/O related parts of thesource code are removed by the C-preprocessor, such that no access to files takes place.

If tables are read from a text file, the file needs to have thefollowing structure ("-----" is not part of the file content):

-----------------------------------------------------#1double tab1(5,2)   # comment line  0   0  1   1  2   4  3   9  4  16double tab2(5,2)   # another comment line  0   0  2   2  4   8  6  18  8  32-----------------------------------------------------

Note, that the first two characters in the file need to be"#1" (a line comment defining the version number of the file format).Afterwards, the corresponding matrix has to be declaredwith type (= "double" or "float"), name and actual dimensions.Finally, in successive rows of the file, the elements of the matrixhave to be given. The elements have to be provided as a sequence ofnumbers in row-wise order (therefore a matrix row can span severallines in the file and need not start at the beginning of a line).Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4).Number separators are spaces, tab (\\t), comma (,), or semicolon (;).Several matrices may be defined one after another. Line comments startwith the hash symbol (#) and can appear everywhere.Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored.Other characters, like trailing non comments, are not allowed in the file.

MATLAB is a registered trademark of The MathWorks, Inc.

Parameters

CombiTable1Dv_0

NameLabelDescriptionData TypeValid Values

mo_n

n

Number of inputs (= number of outputs)

Scalar

mo_u_min

u_min

Minimum abscissa value defined in table

Scalar

mo_u_max

u_max

Maximum abscissa value defined in table

Scalar

mo_tableID

tableID

External table object

Scalar

mo_tableOnFile

tableOnFile

= true, if table is defined on file or in function usertab

Scalar

true
false

mo_table

table

Table matrix (grid = first column; e.g., table=[0, 0; 1, 1; 2, 4])

Matrix

mo_tableName

tableName

Table name on file or in function usertab (see docu)

String

mo_fileName

fileName

File where matrix is stored

String

mo_verboseRead

verboseRead

= true, if info message that file is loading is to be printed

Scalar

true
false

mo_columns

columns

Columns of table to be interpolated

Vector

mo_smoothness

smoothness

Smoothness of table interpolation

Structure

mo_smoothness/choice1

Modelica.Blocks.Types.Smoothness.LinearSegments

Number

0
1

mo_smoothness/choice2

Modelica.Blocks.Types.Smoothness.ContinuousDerivative

Number

0
1

mo_smoothness/choice3

Modelica.Blocks.Types.Smoothness.ConstantSegments

Number

0
1

mo_smoothness/choice4

Modelica.Blocks.Types.Smoothness.MonotoneContinuousDerivative1

Number

0
1

mo_smoothness/choice5

Modelica.Blocks.Types.Smoothness.MonotoneContinuousDerivative2

Number

0
1

mo_smoothness/choice6

Modelica.Blocks.Types.Smoothness.ModifiedContinuousDerivative

Number

0
1

mo_extrapolation

extrapolation

Extrapolation of data outside the definition range

Structure

mo_extrapolation/choice1

Modelica.Blocks.Types.Extrapolation.HoldLastPoint

Number

0
1

mo_extrapolation/choice2

Modelica.Blocks.Types.Extrapolation.LastTwoPoints

Number

0
1

mo_extrapolation/choice3

Modelica.Blocks.Types.Extrapolation.Periodic

Number

0
1

mo_extrapolation/choice4

Modelica.Blocks.Types.Extrapolation.NoExtrapolation

Number

0
1

mo_verboseExtrapolation

verboseExtrapolation

= true, if warning messages are to be printed if table input is outside the definition range

Scalar

true
false

CombiTable1Dv_1

NameLabelDescriptionData TypeValid Values

mo__nmodifiers

Number of Modifiers

Specifies the number of modifiers

Number

mo__modifiers

Modifiers

Add new modifier

Structure

mo__modifiers/varname

Variable name

Cell of strings

mo__modifiers/attribute

Attribute

Cell of strings

'start'
'fixed'

mo__modifiers/value

Value

Ports

NameTypeDescriptionIO TypeNumber

u

implicit

Connector of Real input signals

input

1

y

implicit

Connector of Real output signals

output

1

See Also