Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 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
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,51 @@ | ||
program test_secant | ||
use types, only: dp | ||
use utils, only: assert | ||
use optimize, only: secant | ||
implicit none | ||
|
||
real(dp) :: x | ||
|
||
x = secant(f1, 0.0_dp, 0.1_dp, 1e-12_dp) | ||
print *, x | ||
call assert(abs(x - 0.73908513_dp) < 1e-8_dp) | ||
|
||
x = secant(f2, -4._dp, 4._dp, 1e-12_dp) | ||
print *, x | ||
call assert(abs(x - 0.86547403_dp) < 1e-8_dp) | ||
|
||
x = secant(f3, 0._dp, 3._dp, 1e-12_dp) | ||
print *, x | ||
call assert(abs(x - 2.40482556_dp) < 1e-8_dp) | ||
|
||
x = secant(f3, 3._dp, 6._dp, 1e-12_dp) | ||
print *, x | ||
call assert(abs(x - 5.52007811_dp) < 1e-8_dp) | ||
|
||
x = secant(f4, -4._dp, 4._dp, 1e-12_dp) | ||
print *, x | ||
call assert(abs(x) < 1e-8_dp) | ||
|
||
contains | ||
|
||
real(dp) function f1(x) | ||
real(dp), intent(in) :: x | ||
f1 = cos(x) - x | ||
end function | ||
|
||
real(dp) function f2(x) | ||
real(dp), intent(in) :: x | ||
f2 = cos(x) - x**3 | ||
end function | ||
|
||
real(dp) function f3(x) | ||
real(dp), intent(in) :: x | ||
f3 = bessel_jn(0, x) | ||
end function | ||
|
||
real(dp) function f4(x) | ||
real(dp), intent(in) :: x | ||
f4 = x | ||
end function | ||
|
||
end program |