Functions to perform interpolation.
Performs linear interpolation between the two nearest points in the dataset.
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.
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
Type | Intent | Optional | 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. |
Predicted value at position x
Type | Intent | Optional | 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. |
Predicted value at position x
Type | Intent | Optional | 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. |
Predicted value at position x