-
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.
Add test routine for root finding and minor change to mueller to help…
… avoid NaN.
- Loading branch information
1 parent
826a19b
commit 37a5413
Showing
6 changed files
with
114 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ lib/* | |
# Test binaries | ||
test_ode | ||
test_integ | ||
test_root | ||
test_stats |
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
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,62 @@ | ||
with Ada.Numerics.Generic_Elementary_Functions; | ||
with Ada.Text_IO; | ||
with BBS.Numerical; | ||
with BBS.Numerical.roots_real; | ||
|
||
procedure test_root is | ||
subtype real is Long_Float; | ||
package root is new BBS.Numerical.roots_real(real); | ||
package float_io is new Ada.Text_IO.Float_IO(real); | ||
package elem is new Ada.Numerics.Generic_Elementary_Functions(real); | ||
|
||
function f1(x : real) return real is | ||
begin | ||
return (100.0/(x*x))*elem.sin(10.0/x); | ||
end; | ||
|
||
function f2(x : real) return real is | ||
begin | ||
return x*x*x + 4.0*x*x - 10.0; | ||
end; | ||
|
||
r : real; | ||
l : real; | ||
u : real; | ||
err : root.errors; | ||
begin | ||
Ada.Text_IO.Put_Line("Testing some of the numerical routines."); | ||
-- | ||
Ada.Text_IO.Put_Line("Testing root finding:"); | ||
l := 1.0; | ||
u := 2.0; | ||
r := root.bisection(f2'Access, l, u, 13, err); | ||
Ada.Text_IO.Put(" Bisection gives root at"); | ||
float_io.Put(r, 2, 9, 0); | ||
Ada.Text_IO.Put(", in range "); | ||
float_io.Put(l, 2, 6, 0); | ||
Ada.Text_IO.Put(" to "); | ||
float_io.Put(u, 2, 6, 0); | ||
Ada.Text_IO.Put_Line(", with error code " & root.errors'Image(err)); | ||
-- | ||
l := 1.0; | ||
u := 2.0; | ||
r := root.seacant(f2'Access, l, u, 13, err); | ||
Ada.Text_IO.Put(" Seacant gives root at"); | ||
float_io.Put(r, 2, 9, 0); | ||
Ada.Text_IO.Put(", in range "); | ||
float_io.Put(l, 2, 6, 0); | ||
Ada.Text_IO.Put(" to "); | ||
float_io.Put(u, 2, 6, 0); | ||
Ada.Text_IO.Put_Line(", with error code " & root.errors'Image(err)); | ||
-- | ||
l := 1.0; | ||
u := 2.0; | ||
r := root.mueller(f2'Access, l, u, 13, err); | ||
Ada.Text_IO.Put(" Mueller gives root at"); | ||
float_io.Put(r, 2, 9, 0); | ||
Ada.Text_IO.Put(", in range "); | ||
float_io.Put(l, 2, 6, 0); | ||
Ada.Text_IO.Put(" to "); | ||
float_io.Put(u, 2, 6, 0); | ||
Ada.Text_IO.Put_Line(", with error code " & root.errors'Image(err)); | ||
end test_root; |
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,15 @@ | ||
with "../BBS_Numerical.gpr"; | ||
|
||
project test_root is | ||
for languages use ("Ada"); | ||
for Source_Dirs use ("."); | ||
for Object_Dir use "../obj"; | ||
for Main use ("test_root.adb"); | ||
for Exec_Dir use "."; | ||
package builder is | ||
for switches ("Ada") use ("-s"); | ||
end builder; | ||
package compiler is | ||
for switches ("Ada") use ("-g", "-gnateE", "-gnata"); | ||
end compiler; | ||
end test_root; |