test Program

Uses

  • program~~test~~UsesGraph program~test test module~fmin_module fmin_module program~test->module~fmin_module iso_fortran_env iso_fortran_env module~fmin_module->iso_fortran_env

Tests for fmin_module.


Calls

program~~test~~CallsGraph program~test test proc~fmin fmin_module::fmin program~test->proc~fmin

Variables

Type Attributes Name Initial
real(kind=wp) :: ax
real(kind=wp) :: bx
real(kind=wp) :: xmin
real(kind=wp) :: xerr
real(kind=wp) :: x
real(kind=wp), parameter :: pi = acos(-1.0_wp)
real(kind=wp), parameter :: tol = 1.0e-8_wp

Functions

function func(x) result(f)

Test function to minimize.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x

indep. variable

Return Value real(kind=wp)

function value f(x)


Source Code

    program test

    use fmin_module,  wp => fmin_rk

    real(wp) :: ax, bx, xmin, xerr, x

    real(wp),parameter :: pi  = acos(-1.0_wp)
    real(wp),parameter :: tol = 1.0e-8_wp

    ax = -4.0_wp
    bx = 0.0_wp
    x = -pi/2.0_wp  ! actual answer

    xmin = fmin(func,ax,bx,tol)

    xerr = xmin - x  ! difference from try value

    write(*,*) 'xmin       = ', xmin
    write(*,*) 'xmin exact = ', x
    write(*,*) 'xmin error = ', xerr

    if (abs(xerr) > 10.0_wp * tol) then
        error stop 'test failed'
    end if

    contains
!*****************************************************************************************

!*****************************************************************************************
!>
!  Test function to minimize.

    function func(x) result(f)

    implicit none

    real(wp),intent(in) :: x  !! indep. variable
    real(wp)            :: f  !! function value `f(x)`

    f = sin(x)

    end function func
!*****************************************************************************************

!*****************************************************************************************
    end program test