10.07.2015 Views

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

210 van Wijngaarden, et al.!ALGOL <strong>68</strong> Revised Report211endif x >_ O then rp .L ip else abs ip .L (y >-01 rp l - rp) fiCalls {5.4.3} using compsqrt:compsqrt (w)compsqrt (-3.14)compsqrt (-1)11.2. Innerproduct 1proc innerproduct I = (int n, proc (int) real x, y) real :¢ the innerproduct of two vectors, each with 'n' comppnents, x (i),y (i), i = 1 ..... n, where 'x' and 'y' are arbitrary mappings frominteger to real number ¢begin long real s : = long O;for i ton do s + : = leng x (i) x leng y (i) od;shorten sendReal-calls using innerproduct 1:innerproduct I (m, (intj) real : xl [j], (intj) real : yl [j])innerproduct I (n, nsin, ncos)11.3. Innerproduct 2proc innerproduct 2 = (ref [ ] real a, b) real :if upb a - Iwb a = upb b - Iwb bthen ¢ the innerproduct of two vectors 'a' and 'b' with equal numbersof elements ¢long real s : = long O;ref[ ] realal =a [@I], bl =b [@•];¢ note that the bounds of 'a [@ 1 ]' are [1 : upb a - Iwb a + 1 ] ¢for i to upb al do s +: = leng al [i] x leng b l [i] od;flshorten sReal-calls using innerproduct2:innerproduct 2 (xl, yl)innerproduct 2 (y2 [2, ], y2 [ ,3 ])begin y := - 1;for p from I Iwb a to I upb aenddoodfor q from 2 Iwb a to 2 upb adoifabsa [p, q] > y then y := abs a [i := p, k := q] flodCalls using absmax:absmax (x2, x, i, j)absmax (x2, x, Ioc int, Ioc int)11.5. Euler summationproc euler = (proc (int) real f, real eps, int tim) real :¢ the sum for 'i' from 1 to infinity of 'f(i)', computed by means ofa suitably refined Euler transformation. The summation isterminated when the absolute values of the terms of thetransformed series are found to be less than 'eps' 'tim' times insuccession. This transformation is particularly efficient in thecase of a slowly convergent or divergent alternating series ¢begin int n : = l, t; real mn, ds : = eps; [1 : 16]realm;realsum := (m [1] :=f(1)) /2;for i from 2 while (t := (abs ds < eps ] t + 111)) ~ timdo mn : = f(/kfork to n do mn := ((ds := mn) + m [ k ]) / 2; m [k] := ds od;sum +: = (ds := (abs mn < abs m In] ^ n < 16 f n +: = 1; m In] := mn;mn / 21 mn))od;sumendA call using euler:euler ((int i) real : (odd i j - 1 / i ] 1 / i), 11o-5, 2)11.6. The norm of a vector11.4. Largest elementproc absmax = (ref [, ] real a, ¢ result ¢ ref real y,¢ subscripts ¢ refint i, k) void :¢ the absolute value of the element of greatest absolute value ofthe matrix 'a' is assigned to 'y', and the subscripts of this elementto 'i' and 'k'¢proc norm = (ref [ ] real a) real :¢ the euclidean norm of the vector 'a' ¢(long real s : = long O;fork from lwb a to upb a do s + : = leng a [k]shorten long sqrt (s))For a use of norm in a call, see 11.7.! 2 od;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!