LGF_RegressionLine (FC / V3.0.1)


Author: Siemens Digital Industry

Short description

The simplest case of a regression is the regression line. This means that the assumed relationship between the input and output signal is a linear straight line.

Figure: Regression line

LGF_RegressionLine

Block Interface

LGF_RegressionLine (FC)
   Ret_Val  Void
    
   slope  LReal
    
   intercept  LReal
    
   error  Bool
    
   status  Word
    
Array[*] of LGF_typeRegressionLine  values  Array[*] of LGF_typeRegressionLine
       
   

Output parameter

IdentifierData typeDescription
Ret_ValVoidVoid - Function has no return value
slopeLRealGradient of straight line
interceptLRealThe intersection with the Y axis
errorBoolFALSE: No error
TRUE: An error occurred during the execution of the FB
statusWord16#0000-16#7FFF: Status of the FB
16#8000-16#FFFF: Error identification (see following Table)

In/Out parameter

IdentifierData typeDescription
valuesArray[*] of LGF_typeRegressionLineThe data points are transferred with their X- and Y-values.
The data type `LGF_typeRegressionLine` has the following structure:
• x (Real)
• y (Real)

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_EXECUTION_FINISHED
Status: Execution finished without errors
16#8200ERR_NOT_ENOUGH_VALUES
Error: Not enough Values. The block requires at least two pairs of values to calculate a regression line. Increase the size of the array at the input parameter `values` in the second dimension.

User defined datatype(s)

LGF_typeRegressionLine (UDT)

The data type is for transferring datapoints (Key- Value pairs) to LGF_RegressionLine and calculate the interpolated linear equation parameters slope and intercept.

IdentifierData typeDefault valueDescription
xReal0.0X-Axis value
yReal0.0Y-Axis value

Functional description

The block calculates the regression line with the following line equation:
f(x) = m \cdot x + t
m: Gradient of straight line
t: Intersection with y-axis
N: number of array elements

The gradient m is calculated using the following equation:

m = \frac{n \cdot \sum_{1}^{N}(x(n) \cdot y(n)) - (\sum_{1}^{N}x(n) \cdot \sum_{1}^{N}y(n))}{n \cdot \sum_{1}^{N} x^2(n) - (\sum_{1}^{N}x(n))^2}

The intersection t with the Y axis is calculated using the following equation:

t = \frac{\sum_{1}^{N} y(n)}{N} - b \cdot \frac{\sum_{1}^{N} x(n)}{N}

Change log

Version & DateChange description
01.00.00Siemens Industry Online Support
23.11.2018First released version
01.00.04Simatic Systems Support
15.11.2019Code refactoring, comments added
03.00.00Simatic Systems Support
23.04.2020Set version to V3.0.0, harmonize the version of the whole library
03.00.01Simatic Systems Support
06.04.2021Insert documentation