************80
! INTERP_LAGRANGE applies Lagrange polynomial interpolation to data.
Discussion:
From a space of DIM_NUM dimensions, we are given a sequence of
DATA_NUM points, which are presumed to be successive samples
from a curve of points P.
We are also given a parameterization of this data, that is,
an associated sequence of DATA_NUM values of a variable T.
Thus, we have a sequence of values P(T), where T is a scalar,
and each value of P is of dimension DIM_NUM.
We are then given INTERP_NUM values of T, for which values P
are to be produced, by linear interpolation of the data we are given.
Note that the user may request extrapolation. This occurs whenever
a T_INTERP value is less than the minimum T_DATA or greater than the
maximum T_DATA. In that case, extrapolation is used.
Note that, for each spatial component, a polynomial of degree
( DATA_NUM - 1 ) is generated for the interpolation. In most cases,
such a polynomial interpolant begins to oscillate as DATA_NUM
increases, even if the original data seems well behaved. Typically,
values of DATA_NUM should be no greater than 10!
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
03 December 2007
Author:
John Burkardt
Parameters:
Input, integer ( kind = 4 ) DIM_NUM, the spatial dimension.
Input, integer ( kind = 4 ) DATA_NUM, the number of data points.
Input, real ( kind = 8 ) T_DATA(DATA_NUM), the value of the
independent variable at the sample points.
Input, real ( kind = 8 ) P_DATA(DIM_NUM,DATA_NUM), the value of the
dependent variables at the sample points.
Input, integer ( kind = 4 ) INTERP_NUM, the number of points
at which interpolation is to be done.
Input, real ( kind = 8 ) T_INTERP(INTERP_NUM), the value of the
independent variable at the interpolation points.
Output, real ( kind = 8 ) P_INTERP(DIM_NUM,DATA_NUM), the interpolated
values of the dependent variables at the interpolation points.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=4) | :: | dim_num | ||||
integer(kind=4) | :: | data_num | ||||
real(kind=8) | :: | t_data(data_num) | ||||
real(kind=8) | :: | p_data(dim_num,data_num) | ||||
integer(kind=4) | :: | interp_num | ||||
real(kind=8) | :: | t_interp(interp_num) | ||||
real(kind=8) | :: | p_interp(dim_num,interp_num) |
subroutine interp_lagrange ( dim_num, data_num, t_data, p_data, interp_num, & t_interp, p_interp ) !*****************************************************************************80 ! !! INTERP_LAGRANGE applies Lagrange polynomial interpolation to data. ! ! Discussion: ! ! From a space of DIM_NUM dimensions, we are given a sequence of ! DATA_NUM points, which are presumed to be successive samples ! from a curve of points P. ! ! We are also given a parameterization of this data, that is, ! an associated sequence of DATA_NUM values of a variable T. ! ! Thus, we have a sequence of values P(T), where T is a scalar, ! and each value of P is of dimension DIM_NUM. ! ! We are then given INTERP_NUM values of T, for which values P ! are to be produced, by linear interpolation of the data we are given. ! ! Note that the user may request extrapolation. This occurs whenever ! a T_INTERP value is less than the minimum T_DATA or greater than the ! maximum T_DATA. In that case, extrapolation is used. ! ! Note that, for each spatial component, a polynomial of degree ! ( DATA_NUM - 1 ) is generated for the interpolation. In most cases, ! such a polynomial interpolant begins to oscillate as DATA_NUM ! increases, even if the original data seems well behaved. Typically, ! values of DATA_NUM should be no greater than 10! ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 03 December 2007 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) DIM_NUM, the spatial dimension. ! ! Input, integer ( kind = 4 ) DATA_NUM, the number of data points. ! ! Input, real ( kind = 8 ) T_DATA(DATA_NUM), the value of the ! independent variable at the sample points. ! ! Input, real ( kind = 8 ) P_DATA(DIM_NUM,DATA_NUM), the value of the ! dependent variables at the sample points. ! ! Input, integer ( kind = 4 ) INTERP_NUM, the number of points ! at which interpolation is to be done. ! ! Input, real ( kind = 8 ) T_INTERP(INTERP_NUM), the value of the ! independent variable at the interpolation points. ! ! Output, real ( kind = 8 ) P_INTERP(DIM_NUM,DATA_NUM), the interpolated ! values of the dependent variables at the interpolation points. ! implicit none integer ( kind = 4 ) data_num integer ( kind = 4 ) dim_num integer ( kind = 4 ) interp_num real ( kind = 8 ) l_interp(1:data_num,1:interp_num) real ( kind = 8 ) p_data(dim_num,data_num) real ( kind = 8 ) p_interp(dim_num,interp_num) real ( kind = 8 ) t_data(data_num) real ( kind = 8 ) t_interp(interp_num) ! ! Evaluate the DATA_NUM Lagrange polynomials associated with T_DATA(1:DATA_NUM) ! for the interpolation points T_INTERP(1:INTERP_NUM). ! call lagrange_value ( data_num, t_data, interp_num, t_interp, l_interp ) ! ! Multiply P_DATA(1:DIM_NUM,1:DATA_NUM) * L_INTERP(1:DATA_NUM,1:INTERP_NUM) to get ! P_INTERP(1:DIM_NUM,1:INTERP_NUM). ! p_interp(1:dim_num,1:interp_num) = & matmul ( p_data(1:dim_num,1:data_num), l_interp(1:data_num,1:interp_num) ) return end subroutine interp_lagrange