Sunteți pe pagina 1din 3

11 Math Functions

11 Math Functions

"Math functions" include the following: 11.1 Processing a Math Function


> Sine, cosine, tangent A math function takes the number in accumula-
tor 1 as input value for the function to be exe-
> Arc sine, arc cosine, arc tangent
cuted and stores the result in accumulator 1.
> Squaring, square-root extraction You program a math function according to the
following general schematic:
> Exponential function to base e, Load Address;
natural logarithm , Math function i» i 'i'
Transfer Result;
All math functions process numbers in data for-
mat REAL. Depending on the result, a math A math function alters only the contents of ac-
function sets status bits CCO, CC1, OV and OS cumulator 1; the contents of all other accumu-
as described in Chapter 15 "Status Bits". lators remain unchanged. A math function is
executed without regard to any conditions.
The statements for the STL programming lan-
Table 11.1 shows three examples of math func-
guage are described in this chapter. In the SCL
tions. A math function computes in accordance
programming language, the math functions are
with the rules governing REAL numbers, even
included among the SCL standard functions
when absolute addressing is used and no data
(Chapter 30.3 "Math Functions").
types are declared.
The examples in this chapter are also on the dis- If accumulator 1 contains an invalid REAL
kette which accompanies the book in the STL_ number at the time the function is executed, the
Book library under the "Digital Functions" pro- math function returns an invalid REAL number
gram in function block FB 111 or source file and sets status bits CCO, CC1, OV and OS to
461 «
Chap_ll.

Table 11.1 Examples of Math Functions


Sine The value in memory doubleword MD 110 con- L MD 110;
tains an angle in radian measure. The sine of this SIN ;
angle is generated and stored in memory dou- T MD 104;
bleword MD 104.
Square root The square root of the value in variable L " Global_DB " . MathValuel ;
"MathValuel" is generated and stored in the SQRT;
variable "MathRoot". T " Global_DB " . MathRoot ;
Exponent Variable #Result contains the power of e and L #Exponent;
#Exponent. EXP ;
T #Result;

201
11 Math Functions

11.2 Trigonometric Functions 11.3 Arc Functions

The trigonometric functions The arc functions (inverse trigonometric func-


tions)
t> SIN Sine,
> ASIN Arc sine,
D> COS Cosine and

> TAN Tangent > ACOS Arc cosine and

assume an angle in radian measure in form, of a > ATAN Arc tangent


REAL number in accumulator 1.
are the inverse functions of the corresponding
Two units are normally used for the size of an trigonometric functions. They assume a REAL
angle: degrees from 0° to 360° and radian mea- number in a specific range in accumulator 1,
sure from 0 to ITT (where TT = +3.141593e+00). and return an angle in radian measure (Table
Both can be converted proportionally. For ex- 11.2).
ample, the radian measure for a 90° angle is IT/
2 or+1.570796e+00. If the permissible range is exceeded, the arc
function returns an invalid REAL number and
With values greater than 2ir (+6.283185e+00), sets status bits CCO, CC1, OV and OS to "1".
ITT or a multiple thereof is subtracted until the
input value for the trigonometric function is Example: In a right-angled triangle, one of the
less than ITT. short sides of the triangle and the hypotenuse
form an aspect ratio of 0.343. How big is the
Example: angle between them in degrees?
Computing the idle power
Ps = U x I x sin(cp) Arcsin (0.343) returns the angle in radian
measure; multiplication with factor 360/277 (=
L PHI; 57.2958) gives you the angle in degrees
SIN (approx. 20°).
L Current;
L 0.343;
*R
ASIN ;
L Voltage;
L 57.2958;
*R
*R
T I_Power;
T Angle_Degree;
Please note that the angle must be specified in
radian measure. If an angle is available in de-
grees, you must multiply it by the factor

77/180 =+1.745329e-02 11.4 Other Math Functions


before you can process it with a trigonometric
function. The following math functions are also available

> SQR Squaring,


Table 11.2 Value Ranges for Arc Functions
Function Permissible Value Value Returned > SQRT Square-root extraction,
Range
ASIN -1 to +1 -IT/2 to +7T/2 > EXP Exponential function to base e and
ACOS -1 to +1 OtOTT
> LN Compute natural logarithm
ATAN Entire range -7T/2 to +7T/2 (logarithm to base e).

202
11.4 Other Math Functions

Squaring Example: Any power can be computed with the


The SQR function squares the value in accumu- formula
lator 1.
Example:
Computing the volume of a cylinder V =
L Value_a;
L Radius;
SQR
LN ;
L Height; L Value_b;
*R *R ;
L 3.141592;
. EXP ;
*R r
T Volume; T Power;

Square-root extraction Computing the natural logarithm


The SQRT function extracts the square root of The LN function computes the natural loga-
the value in accumulator 1. If the value in accu- rithm to base e (= 2.718282e+00) from the
mulator 1 is less than zero, SQRT sets status number in accumulator 1. If accumulator 1 con-
bits CCO, CC1, OV and OS to "1" and returns tains a value less than or equal to zero, LN sets
an invalid REAL number. If accumulator 1 con- status bits CCO, CC1, OV and OS to "1" and re-
tains -0 (minus zero), —0 is returned. turns an invalid REAL number.
Example: c = The natural logarithm is the inverse of the ex-
ponential function: If y = QX then x = In (y).
L #a;
SQR ; Example: Computing a logarithm to base 10
L #b; and to any other base.
SQR ;
+R ; The basic formula is
SQRT ;
T #c;

(If a or b is declared as a local variable, it must


be preceded by # if the compiler is to recognize where b or n is any base. If you make n = e, you
it as a local variable; if a or b is a global vari- can compute a logarithm to any base using the
able, it must be enclosed in quotation marks.) natural logarithm:

Exponentiation to base e
The EXP function computes the power from In the special case for base 10, the formula is:
base e (= 2.718282e+00) and the value in accu-
mulator 1 (eAccul). lga = In a = 0.4342945 • In a
hTTO

203

S-ar putea să vă placă și