PROG
a) Compute
SUM FROM {I=1} TO N I
(u415)
b) Compute
PI FROM {I=1} TO N I
(u415a)
c) Compute
SUM FROM {I=1} TO N {PI FROM {J=I} TO N J}
(u415b)
PED
To learn how to convert Sigma and Pi notation
CONCEPTS
can be translated as:
SUM FROM {I=a} TO b expr(I)
I:=a;
SUM:=0;
while(I<=b) DO BEGIN
SUM:=SUM+expr(I);
I:=I+1;
end;
I:=a;
PROD FROM {I=a} TO b expr(I)
PRODUCT:=1
while(I<=b) DO BEGIN
PRODUCT:=PRODUCT*expr(I);
I:=I+1;
end;
In the event that sigma's and pi's nested, work from the outside in.
Sigma and Pi notation shows up frequently in mathematical
textbooks, journals and in descriptions of numerical analysis
recipes of all kinds. Thus, those of a mathematical bent, should
learn how to convert these into PASCAL--what's discussed in this
unit.
means expr(a) + expr (a+1) ... expr (b)
SUM FROM {I=a} TO b expr(I)
means expr (a) * expr (a+1) ... expr (b)
PROD FROM {I=a} TO b expr(I)
The first program translates:
This is simply the sum of the integers from 1 to n. In our
template a is 1 and b is n. E.G., if N were 5, this would compute
1+2+3+4+5.
SUM FROM {I=1} TO N I
The expr(i) is simply i, so we add i to SUM in the template. Look
at line 11.
The second program translates:
This is simply the product of the integers from 1 to n, otherwise
known as n!. In our template, a is the 1 and B is N. If N were 5,
this would compute 1*2*3*4*5.
PI FROM {I=1} TO N I
The last program computes:
We have an outer loop from lines 8 to 10 and line 17 to 19. Note
that we simply use the sum template. We add product, which is
computed in lines 11 to 16 according to the product template we saw
earlier.
SUM FROM {I=1} TO N {PI FROM {J=I} TO N J}