lin_interp Interface

public interface lin_interp

Performs linear interpolation between the two nearest points in the dataset.

Syntax

 y = lin_interp(x, known_xs, known_ys)

Where:

  • x: Data point to be predicted.
  • known_xs: Independent array of data, known X values.
  • known_ys: Dependent array of data, known Y values.

It returns the predicted value y at position x, by linear interpolation between the nearest points to x in known_xs.

If known_xs and known_ys do not have the same size, it will return nan. If known_xs is not ascending ordered, it will return nan.

Note that this function does not extrapolate. * If x is lower than known_xs(1), the returned value will be known_ys(1). * If x is larger than known_xs(N), the returned value will be known_ys(N), where N is the last index in the arrays.

Example

The following program performs a linear interpolation:

 PROGRAM lin_interpExample
    USE FU_Interpolation, ONLY: lin_interp
    IMPLICIT NONE
    REAL,DIMENSION(6) :: X = (/1., 2., 3., 4., 5., 6./)
    REAL,DIMENSION(6) :: Y = (/0.9, 2.6, 4.3, 8.2, 10.0, 11.1/)
    WRITE(*,*) lin_interp(4.4., X, Y)
 END PROGRAM lin_interpExample

Contents


Module Procedures

private pure function lin_interp_sp(x, known_xs, known_ys) result(y)

Arguments

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

Data point to be predicted

real(kind=prec), intent(in), DIMENSION(:) :: known_xs

Independent array of data, known X values.

real(kind=prec), intent(in), DIMENSION(:) :: known_ys

Dependent array of data, known Y values.

Return Value real(kind=prec)

Predicted value at position x

private pure function lin_interp_dp(x, known_xs, known_ys) result(y)

Arguments

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

Data point to be predicted

real(kind=prec), intent(in), DIMENSION(:) :: known_xs

Independent array of data, known X values.

real(kind=prec), intent(in), DIMENSION(:) :: known_ys

Dependent array of data, known Y values.

Return Value real(kind=prec)

Predicted value at position x

private pure function lin_interp_qp(x, known_xs, known_ys) result(y)

Arguments

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

Data point to be predicted

real(kind=prec), intent(in), DIMENSION(:) :: known_xs

Independent array of data, known X values.

real(kind=prec), intent(in), DIMENSION(:) :: known_ys

Dependent array of data, known Y values.

Return Value real(kind=prec)

Predicted value at position x