-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some refactoring and updating comments in root finding. Add trapezoid…
… rule for integration.
- Loading branch information
1 parent
20fcc34
commit d66dd2c
Showing
5 changed files
with
56 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package body BBS.integration_real is | ||
-- | ||
function trapezoid(test : test_func; lower, upper : f; steps : Positive) return f is | ||
accumulator : f := 0.0; | ||
last_func : f := test(lower); | ||
next_func : f; | ||
base : f := lower; | ||
step_size : f := (upper - lower)/f(steps); | ||
begin | ||
for i in 0 .. steps - 1 loop | ||
base := base + step_size; | ||
next_func := test(base); | ||
accumulator := accumulator + ((next_func + last_func)/2.0)*step_size; | ||
last_func := next_func; | ||
end loop; | ||
return accumulator; | ||
end; | ||
-- | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generic | ||
type F is digits <>; | ||
package BBS.integration_real is | ||
type test_func is access function (x : f) return f; | ||
-- | ||
-- Integrate the provided function between the lower and upper limits using | ||
-- the composite trapezoid method with the specified number of steps. | ||
-- | ||
function trapezoid(test : test_func; lower, upper : f; steps : Positive) return f; | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters