SIGMA

Contents


sigma is used to find the sum of a series of numerical expressions or the concatenation of a series of alphanumeric expressions dependent on an index, that varies between two limits in steps of 1.

 

Syntaxes

   sigma( [ variable = ] indice_start, indice_end, expression )

 

Parameters

Element

Description

Restrictions

variable

Name of the loop variable used in the
form:
[ classe ] nom_de_variable
The Adonix system variable indcum is used as the default.

None.

indice_start

Numerical expression stating the start of the range over which the variable may vary.

None.

indice_end

Numerical expression stating the end of the range over which the variable may vary.

None.

expression

Numerical or alphanumerical expression.

None.

 

Examples

   # The 26 letters of the alphabet
    ALPHABET = sigma( I = 1, 26, chr$(64+I) )
   # Construction of a random string of MAXL alphabetic characters.
    CHAINE_H = sigma( 1, MAXL, chr$(65 + int(rnd(25))) )
   # Sum of squares of numbers from 1 to N
    SOMME_CARRES = sigma( I = 1, N, I*I )
   # The same sum with indcum
    SOMME_CARRES = sigma( 1, N, indcum*indcum )
   # Sum of cubes of numbers from 1 to N (by a double sum)
    DOUBLE_SOMME = sigma( I=1, N, sigma(J = 1, I, J*J) )
   # Calculation of a scalar product
    PROD_SCALAIRE = sigma( I = 0, N, S(indcum) * T(indcum) )

 

Description and comments

sigma is used to calculate the total of a numerical expression dependant on an index varying in steps of 1 between two limits or the concatenation of string type variables under the same conditions.

If a range of indices is given, such that there is no element to sum for example sigma(I = 1, 0, I), the result returned is 0 (even if the expression is an alphanumeric type).

The type of result depends on the type of the arguments, that is:

·         concatenation of strings:

·         the result is a Char type,

 

·         numerical total:

·         the result is an Integer type (if there are only integers to be totalled and if the total does not exceed the integer limit), Double (if there is at least one floating point to be totalled), and otherwise Decimal.

 

Comments

indcum is an Integer type variable; it may therefore only be used if it varies within the integer range -2^31 and 2^31-1. Moreover sigma expressions may only be nested if the index variable is different from indcum.

If the loop variable does not exist, it is created as a Decimal type.

The final value of the index matches the first value outside the given range.

 

Associated errors

Error

Description

ERMODE (10)

The indices given are not numerical.

 

Associated key words

SUM - INDCUM - FOR


CONTENTS


Copyright © Sage 1999 - 2007