Yurttas/PL/IL/Ada-95/ProgUnits/A/integrate 00 p.adb

From ZCubes Wiki
Jump to navigation Jump to search
 1--
 2-- Copyright (C) 1998
 3-- All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4--
 5-- Permission to use, copy, modify, and distribute this 
 6-- software and its documentation for EDUCATIONAL purposes
 7-- and without fee is hereby granted provided that this 
 8-- copyright notice appears in all copies. 
 9-- 
10-- 
11 
12-- date   : January 1, 1998.
13-- author : Salih Yurttas.
14
15-- integrate_00_p.adb
16
17
18package body Integrate_00_P is
19  
20  -- evaluates approximately the integral of F(x)
21  -- between limits a and b, using the trapezoidal
22  -- rule with 8 intervals
23
24  procedure Integrate(a, 
25                      b        : in Float; 
26                      Integral : out Float) is
27
28    n : Integer := 8;
29
30    w,
31    Sum : Float;
32
33  begin
34
35    w := (b-a)/Float(n);
36    Sum := (F(a)+F(b))/2.0;
37
38    for i in 1 .. n-1
39    loop
40      Sum := Sum + F(a+Float(i)*w);
41    end loop;
42
43    Integral := w * Sum;
44
45  end Integrate;
46
47  function F1(x : in Float) return Float is
48  begin
49    return x*x - (2.0*x) - 1.0;
50  end F1;
51
52  function F2(x : in Float) return Float is
53  begin
54    return x*x*x - x + 2.0;
55  end F2;
56
57end Integrate_00_P;