Siemens PLC. STL

: 2013-02-16

: komatic

: Step7


:
(Power)
(Root)
4 (Polinom)
(log)

: Siemens
STL
2003



mathlib




y = x ^ b

FUNCTION FC 1 : VOID
TITLE =Raises 'x' to the power of 'b'
//y = x ^ b
AUTHOR : AS_CS_21
FAMILY : MATH
NAME : POW
VERSION : 1.0


VAR_INPUT
x : REAL ; //the Base to be raised
b : REAL ; //the Exponent to raise
END_VAR
VAR_OUTPUT
y : REAL ; //the Result of the Calculation
END_VAR
VAR_TEMP
tBase : REAL ;
tExp : REAL ;
Exponent : DINT ; //Schleifenzhler
inverted : BOOL ;
END_VAR
BEGIN
NETWORK
TITLE =Entscheide Sonderflle -> direkt Ausgeben
//y = a^b
L #b;
T #tExp;
L 0.000000e+000;
==R ;
L 1.000000e+000;
JC Fast; //fr alle x aus R gilt: x^0 = 1
TAK ;
L #tExp;
>R ;
= #inverted;
JCN cOne;
NEGR ;
T #tExp;
cOne: L 1.000000e+000;
==R ;
L #x; //fr alle x aus R gilt: x^1 = x
JC Fast;
T #tBase;
TRUNC ;
DTR ;
L #tBase;
==R ;
ON #inverted;
JC vBas;
R #inverted;
L 0.000000e+000;
JC EXIT;
NETWORK
TITLE =Entscheide ganzzahliger Exponent -> Schleife

vBas: L #tExp;
TRUNC ;
DTR ;
L #tExp;
<>R ;
JC cExp; //gebrochen Rationaler Exponent
TRUNC ;
+ L#-1;
PWR: T #Exponent;
L #x;
L #tBase;
*R ;
T #tBase;
L #Exponent;
LOOP PWR;
L #tBase;
JU Fast;
NETWORK
TITLE =Entscheide gebrochenrationaler Exponent -> Exp (#tExp Ln #tBase)

cExp: L #tBase;
LN ;
L #tExp;
*R ;
EXP ;
NETWORK
TITLE =

Fast: AN #inverted;
JC EXIT;
L 1.000000e+000;
TAK ;
/R ;
EXIT: T #y;
BE ;
END_FUNCTION




mathlib

y = x ^ (1/b)

FUNCTION FC 2 : VOID
TITLE =Calculates the 'b'-th root of 'x'
//y = x ^ (1/b)
AUTHOR : AS_CS_21
FAMILY : MATH
NAME : ROOT
VERSION : 1.0


VAR_INPUT
x : REAL ; //the Base of the calculated root
b : REAL ; //the Rootindex to be calculated
END_VAR
VAR_OUTPUT
y : REAL ; //the Result of the Calculation
END_VAR
BEGIN
NETWORK
TITLE =Argumentvalidation

L #b; //eine 0te Wurzel kann nicht gezogen werden
L 0.000000e+000;
<>R ;
A( ;
L #x; //ebenfalls sind Wurzel aus negativen Argumenten
; //nicht in IR definiert
) ;
JC vArg; // Gltige Argumente
TAK ; // Ungltiges Argument
JU EXIT; //Als Ersatzwert 0 ausgeben
NETWORK
TITLE =Calculation of ROOT

//Die Wurzel ist diejenige Zahl y fr die gilt y^b = x. Mit exp(b ln y) = x folgt
//b ln y = ln x und weiter y = exp (ln x/ b), mit b <> 0, x > 0 und b,x aus IR.
vArg: L #x;
LN ;
L #b;
/R ;
EXP ;
EXIT: T #y;
END_FUNCTION




mathlib

y = ax^4 + bx^3 + cx^2 + dx + e

FUNCTION FC 3 : VOID
TITLE =Polynomion of 4th order
//y = ax^4 + bx^3 + cx^2 + dx + e
AUTHOR : AS_CS_21
FAMILY : MATH
NAME : POLY_4
VERSION : 1.0


VAR_INPUT
X : REAL ; //the Variable
a : REAL ; //Coefficient of the 4th Power
b : REAL ; //Coefficient of the 3rd Power
c : REAL ; //Coefficient of the 2nd Power
d : REAL ; //Coefficient of the 1st Power
e : REAL ; //Coefficient of the 0th Power
END_VAR
VAR_OUTPUT
y : REAL ; //the Result of the Calculation
END_VAR
VAR_TEMP
fourth : REAL ;
third : REAL ;
second : REAL ;
first : REAL ;
END_VAR
BEGIN
NETWORK
TITLE =Calculates the 4th power of x
//y = ax^4 + bx^3 + cx^2 + dx + e
L #X;
SQR ;
SQR ;
L #a;
*R ;
T #fourth;
NETWORK
TITLE =Calculates the 3rd power of x

L #X;
SQR ;
L #X;
*R ;
L #b;
*R ;
T #third;
NETWORK
TITLE =Calculates the 2nd power of x

L #X;
SQR ;
L #c;
*R ;
T #second;
NETWORK
TITLE =ax^4 + bx^3 + cx^2 + dx + e

L #X; //y = dx
L #d;
*R ;
L #second; //y = cx^2 + dx
+R ;
L #third; //y = bx^3 + cx^2 + dx
+R ;
L #fourth; //y = ax^4 + bx^3 + cx^2 + dx
+R ;
L #e; //y = ax^4 + bx^3 + cx^2 + dx + e
+R ;
T #y;
END_FUNCTION




mathlib

y = logb(x)

FUNCTION FC 4 : VOID
TITLE =Logarithm of 'x' to base of 'b'
//y = logb(x) -> logarithm of x to the base of b
AUTHOR : AS_CS_21
FAMILY : MATH
NAME : LOG
VERSION : 1.0


VAR_INPUT
x : REAL ; //the Logarithm Argument
b : REAL ; //the Logarithm Base
END_VAR
VAR_OUTPUT
y : REAL ; //the Result of the Calculation
END_VAR
BEGIN
NETWORK
TITLE =

L #x;
L 0.000000e+000;
>R ;
A( ;
L #b;
;
) ;
A( ;
L 1.000000e+000;
<>R ;
) ;
JC cLog;
L 0.000000e+000;
JU EXIT;
NETWORK
TITLE =


cLog: L #x;
LN ;
L #b;
LN ;
/R ;
EXIT: T #y;
END_FUNCTION





: 9707

:     : 2013-02-18

, 4 10-, .

: komatic    : 2013-02-24

,

: XHunter    : 2014-11-30

:

(4000 max):

: