XLPack 6.1
Julia API Reference Manual
Loading...
Searching...
No Matches

◆ pchia()

function pchia ( n::Integer  ,
x::Array{Float64}  ,
f::Array{Float64}  ,
d::Array{Float64}  ,
a::Real  ,
b::Real  ,
incfd::Integer  = 1,
skip::Bool(keyword argument)  = false 
)

Integral of piecewise cubic Hermite / cubic spline function

Purpose
pchia evaluates the definite integral of a piecewise cubic Hermite function over an arbitrary interval. The interpolant is defined by n, x[], f[] and d[] computed by pchim, pchic, pchsp or pchse.
Returns
(s, info)

s (Float64):
Value of the requested integral.

info (Int32):
= 0: Successful exit
= -1: The argument n had an illegal value (n < 2)
= -2: The argument x is invalid (e.g. not distinct, not in increasing order)
= -3: The argument f is invalid
= -4: The argument d is invalid
= -5: The argument incfd had an illegal value (incfd < 1)
= -6: The argument skip had an illegal value (skip != 0 and skip != 1)
= 1: a is outside the interval [x[0], x[n-1]]
= 2: b is outside the interval [x[0], x[n-1]]
= 3: Both of the above are true
Parameters
[in]nNumber of data points. (n >= 2)
[in]x1-dimensional array (Float64, n)
Independent variable values. The elements of x[] must be strictly increasing.
[in]f1-dimensional array (Float64, incfd*(n - 1) + 1)
Function values. f[i*incfd] is the value corresponding to x[i] (i = 0 to n - 1).
[in]d1-dimensional array (Float64, incfd*(n - 1) + 1)
Derivative values. d[i*incfd] is the value corresponding to x[i] (i = 0 to n - 1).
[in]aLower limit of integration.
[in]bUpper limit of integration.
Note - There is no requirement that [a, b] be contained in [x[0], x[n - 1]]. However, the resulting integral value will be highly suspect, if not.
[in]incfd(Optional)
Increment between successive values in f and d. (incfd >= 1) (default = 1)
[in]skip(Optional (keyword argument))
Logical variable which should be set to true if the user wishes to skip checks for validity of preceding parameters, or to false otherwise. This will save time in case these checks have already been performed (say, in pchim, pchic, pchsp or pchse). (default = false)
Reference
SLATEC (PCHIP)
Example Program
Using the following table, compute S = integral of 1/(1 + x^2) dx [0, 4] (= atan(4)).
  x    1/(1 + x^2)
----- -------------
 -1        0.5
  0        1 
  1        0.5 
  2        0.2 
  3        0.1 
  4        0.05882
  5        0.03846
----- -------------
function TestPchia()
n = 7
x = [ -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ]
y = [ 0.5, 1, 0.5, 0.2, 0.1, 0.05882, 0.03846 ]
d = Vector{Cdouble}(undef, n)
info = pchse(n, x, y, d)
println(info)
if info == 0
a = 0.0
b = 4.0
s, info = pchia(n, x, y, d, a, b)
println(s, " ", info)
end
end
function pchia(n::Integer, x::Array{Float64}, f::Array{Float64}, d::Array{Float64}, a::Real, b::Real, incfd::Integer=1, skip::Bool(keyword argument)=false)
Integral of piecewise cubic Hermite / cubic spline function
function pchse(n::Integer, x::Array{Float64}, f::Array{Float64}, d::Array{Float64}, incfd::Integer=1)
Piecewise cubic spline interpolation ("not a knot" condition)
Example Results
> TestPchia()
0
1.310707380952381 0