polynomial Derived Type

type, public :: polynomial

Defines a polynomial, and associated routines for performing polynomial operations.


Contents


Type-Bound Procedures

procedure, public :: companion_mtx => poly_companion_mtx

  • private pure function poly_companion_mtx(this) result(c)

    Returns the companion matrix for the polynomial.

    See Also

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value real(kind=real64), dimension(this%order(), this%order())

    The companion matrix.

generic, public :: evaluate => evaluate_real, evaluate_complex

  • private elemental function poly_eval_double(this, x) result(y)

    Evaluates a polynomial at the specified points.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    real(kind=real64), intent(in) :: x

    The value(s) at which to evaluate the polynomial.

    Return Value real(kind=real64)

    The value(s) of the polynomial at x.

  • private elemental function poly_eval_complex(this, x) result(y)

    Evaluates a polynomial at the specified points.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    complex(kind=real64), intent(in) :: x

    The value(s) at which to evaluate the polynomial.

    Return Value complex(kind=real64)

    The value(s) of the polynomial at x.

procedure, public :: fit => poly_fit

  • private subroutine poly_fit(this, x, y, order, err)

    Fits a polynomial of the specified order to the supplied data set.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    real(kind=real64), intent(in), dimension(:) :: x

    An N-element array containing the independent variable data points. Notice, must be N > order.

    real(kind=real64), intent(inout), dimension(:) :: y

    On input, an N-element array containing the dependent variable data points. On output, the contents are overwritten.

    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 1).

    class(errors), intent(inout), optional, target :: err

    An error handling object.

procedure, public :: fit_thru_zero => poly_fit_thru_zero

  • private subroutine poly_fit_thru_zero(this, x, y, order, err)

    Fits a polynomial of the specified order that passes through zero to the supplied data set.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    real(kind=real64), intent(in), dimension(:) :: x

    An N-element array containing the independent variable data points. Notice, must be N > order.

    real(kind=real64), intent(inout), dimension(:) :: y

    On input, an N-element array containing the dependent variable data points. On output, the contents are overwritten.

    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 1).

    class(errors), intent(inout), optional, target :: err

procedure, public :: get => get_poly_coefficient

  • private function get_poly_coefficient(this, ind, err) result(c)

    Gets the requested polynomial coefficient by index. The coefficient index is established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    integer(kind=int32), intent(in) :: ind

    The polynomial coefficient index.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

    Return Value real(kind=real64)

    The requested coefficient.

procedure, public :: get_all => get_poly_coefficients

  • private pure function get_poly_coefficients(this) result(c)

    Gets an array containing all the coefficients of the polynomial. The coefficient index is established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value real(kind=real64), dimension(this%order() + 1)

    The array of coefficients.

generic, public :: initialize => init_poly, init_poly_coeffs

  • private subroutine init_poly(this, order, err)

    Initializes the polynomial instance.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 0).

    class(errors), intent(inout), optional, target :: err

    An error handling object.

  • private subroutine init_poly_coeffs(this, c, err)

    Initializes the polynomial instance.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    real(kind=real64), intent(in), dimension(:) :: c

    The array of polynomial coefficients. The coefficients are established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

procedure, public :: order => get_poly_order

  • private pure function get_poly_order(this) result(n)

    Returns the order of the polynomial object.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value integer(kind=int32)

    The order of the polynomial. Returns -1 in the event no polynomial coefficients have been defined.

procedure, public :: roots => poly_roots

  • private function poly_roots(this, err) result(z)

    Computes all the roots of a polynomial by computing the eigenvalues of the polynomial companion matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

    Return Value complex(kind=real64), dimension(this%order())

    The roots of the polynomial.

procedure, public :: set => set_poly_coefficient

  • private subroutine set_poly_coefficient(this, ind, c, err)

    Sets the requested polynomial coefficient by index. The coefficient index is established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    integer(kind=int32), intent(in) :: ind

    The polynomial coefficient index.

    real(kind=real64), intent(in) :: c

    The polynomial coefficient.

    class(errors), intent(inout), optional, target :: err

    An error handling object.