solve_polynomial Function

private pure function solve_polynomial(B, x0, error) result(x)

Numerical solution to polynomial equation using Newton-Raphson method

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(0:6) :: B

Polynomial B = B(6) x^6 + B(5) x^5 + ... + B(0)

real(kind=wp), intent(in) :: x0

Initial point

real(kind=wp), intent(in) :: error

Maximum error

Return Value real(kind=wp)

root found after applying Newton-Raphson method to B The function returns the value when the correction is smaller than error.


Called by

proc~~solve_polynomial~~CalledByGraph proc~solve_polynomial geodesy_module::solve_polynomial proc~cartesianintogeodetici geodesy_module::CartesianIntoGeodeticI proc~cartesianintogeodetici->proc~solve_polynomial proc~cartesianintogeodeticii geodesy_module::CartesianIntoGeodeticII proc~cartesianintogeodeticii->proc~solve_polynomial

Source Code

pure function solve_polynomial(B, x0, error) result(x)

    real(wp),dimension(0:6),intent(in) :: B !! Polynomial `B = B(6) x^6 + B(5) x^5 + ... + B(0)`
    real(wp),intent(in) :: x0 !! Initial point
    real(wp),intent(in) :: error !! Maximum error
    real(wp) :: x !! root found after applying Newton-Raphson method to `B`
                  !! The function returns the value when the correction
                  !! is smaller than error.

    real(wp) :: f,fp,corr
    integer :: i, j !! counter

    integer,parameter :: maxiter = 100 !! maximum number of iterations

    x = x0
    do i = 1, maxiter
        f  = B(6)
        do j = 5, 0, -1
            if (j==5) then
                fp = f
            else
                fp = x*fp + f
            end if
            f  = x*f + B(j)
        end do
        if (fp==zero) exit ! singular point
        corr = f/fp
        x = x - corr
        if (abs(corr)<=error) exit
    end do

end function solve_polynomial