identification division.
program-id. simpson.
* aus Wirth, systematisches Programmieren p. 95
author. "JD".
date-written. 11.9.2005.
date-compiled.
data division.
working-storage section.
78 eps pic 9(4)V9(4) comp value 0.0001.
77 i pic 9(4) comp.
77 n pic 9(4) comp.
77 s pic 9(4)V9(4) comp.
77 ss pic 9(4)V9(4) comp.
77 diff pic 9(4)V9(4) comp.
77 s1 pic 9(4)V9(4) comp.
77 s2 pic 9(4)V9(4) comp.
77 s4 pic 9(4)V9(4) comp.
77 h pic 9(4)V9(4) comp.
77 temp1 pic 9(4)V9(4) comp.
linkage section.
77 a pic 9(4)V9(4).
77 b pic 9(4)V9(4).
77 r pic 9(4)V9(4).
procedure division using a b r.
* computes Integral f(x) in [a,b]
move 2 to n
compute h = (b - a) * 0.5
compute s1 = h * (function f(a) + function f(b))
move 0 to s2
compute temp1 = a + h
compute s4 = 4 * h * function f(temp1)
add s1 s2 s4 giving s
subtract ss from s giving diff
perform until function abs(diff) < eps * function abs(s)
move s to ss
multiply 2 by n
divide 2 into h
multiply 0.5 by s1
compute s2 = 0.5 * s2 + 0.25 * s4
move 0 to s4
move 1 to i
perform until i > n
compute temp1 = a + i * h
compute s4 = s4 +function f(temp1)
add 2 to i
end-perform
compute s4 = 4 * h * s4
compute s = s1 + s2 + s4
end-perform
compute r = s / 3.
* now s = s / 3
end-program simpson.
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
|
Haftungshinweis
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.
|