Approximation (FPScript)

21.09.2021

Approximates a linear model Y(X) to given data according to the method of the least square error.

Syntax

Approximation(DataSet, Model)
or
Approximation(Amplitude, Time, Model)

 

The syntax of the Approximation function consists of the following parts:

Part

Description

DataSet

The signal or data series for which the approximation is to be calculated. If you specify a data series, then the X component will be generated automatically.

Permitted data structures are data series und signal. All numeric data types are permitted.

For complex data types the absolute value is formed.

If the argument is a list, then the function is executed for each element of the list and the result is also a list.

Amplitude

A data series with the Y component of a signal. If you specify a signal, then its Y component is used.

Permitted data structures are data series und signal. All numeric data types are permitted.

For complex data types the absolute value is formed.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

Time

A data series with the X component of a signal. If you specify a signal, then its Y component is used.

Permitted data structures are data series und signal. All numeric data types are permitted.

For complex data types the absolute value is formed.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

Model

Specifies the composition of the model function for which the coefficients are determined by the approximation. You can specify custom or predefined element functions.

 

The custom model function is passed as a data series of strings. For instance, the model function Y = A + B * X + C * sin(2 * PI * X) is described by the data series {"1", "X", "sin(2*PI*X)"}.

 

The model function with predefined element functions can be formed by adding the following values. For example, if the desired model function is A + B * X + C * X2, then the Model argument must receive the value APPROX_C + APPROX_X + APPROX_X_2. Approximation then calculates the unknown coefficients A, B and C so that the model function approximates the specified signal as best as possible.

Constant

Meaning

+ APPROX_C

1

+ APPROX_X

X

+ APPROX_X_2

X2

+ APPROX_X_3

X3

+ APPROX_X_4

X4

+ APPROX_X_5

X5

+ APPROX_X_6

X6

+ APPROX_X_7

X7

+ APPROX_X_8

X8

+ APPROX_X_9

X9

+ APPROX_X_10

X10

+ APPROX_X_11

X11

+ APPROX_X_12

X12

+ APPROX_REC

1/X

+ APPROX_REC2

1/X2

+ APPROX_REC3

1/X3

+ APPROX_SIN

sin(X)

+ APPROX_COS

cos(X)

+ APPROX_TAN

tan(X)

+ APPROX_SINH

sinh(X)

+ APPROX_COSH

cosh(X)

+ APPROX_TANH

tanh(X)

+ APPROX_EXP

eX

+ APPROX_EXP2

eX

+ APPROX_LN

log(X)

+ APPROX_LOG

log10(X)

+ APPROX_POW

10X

+ APPROX_POW2

10X

+ APPROX_SQRT

sqrt(X)

+ APPROX_ROOT3

X1/3

Permitted data structures are scalar value und data series. Supported data types are 16-bit integer, 32-bit integer und string.

If the argument is a list, then the first element in the list is taken. If this is also a list, then the process is repeated.

Remarks

As the result the function returns a data series of data type 64-bit floating point.

The number of values equals to the number of element functions of the model function plus one.

The last value represents the goodness-of-fit measure Χ2 (Chi-square). This is the sum of the squares of all deviations of the approximated model function from the data. The smaller Χ2 is, the better the found model function approximates the data. The other values of the data series return the coefficients of the element functions used in the model function, where the order corresponds to the order in the table above.

The following illustration shows measured data of a quadratic characteristic curve and its approximation:

Available in

FlexPro Basic, Professional, Developer Suite

Examples

Dim _c = Approximation(Signal, APPROX_C + APPROX_X + APPROX_X_2)
Signal(_c[0] + _c[1] * (Signal.X) + _c[2] * (Signal.X)^2., Signal.X)
 

Approximates a signal with a quadratic model function.

Dim _c = Approximation(Signal, {"1", "sin(2*PI*X)"})
Signal(_c[0] + _c[1] * sin(2 * PI * Signal.X), Signal.X)
 

Approximates a signal with a custom model function Y(X) = A + B * Sin(2*PI*X).

See Also

Approximation2D Function

HarmonicEstimation Function

NonLinCurveFit Function

Approximation Analysis Object

2D Approximation Analysis Object

Regression Analysis Object

References

[1] "Philip R. Bevington, D. Keith Robinson": "Data Reduction and Error Analysis for the Physical Sciences, 3rd Edition". "McGraw-Hill, New York",2003.ISBN 0-07-247227-8.

Share article or send as email:

You might be interested in these articles