|
|
◆ pchia()
| def pchia |
( |
n |
, |
|
|
x |
, |
|
|
f |
, |
|
|
d |
, |
|
|
a |
, |
|
|
b |
, |
|
|
incfd |
= 1, |
|
|
skip |
= 0 |
|
) |
| |
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 (float):
Value of the requested integral.
info (int):
= 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] | n | Number of data points. (n >= 2) |
| [in] | x | Numpy ndarray (1-dimensional, float, length n)
Independent variable values. The elements of x[] must be strictly increasing. |
| [in] | f | Numpy ndarray (1-dimensional, float, length incfd*(n - 1) + 1)
Function values. f[i*incfd] is the value corresponding to x[i] (i = 0 to n - 1). |
| [in] | d | Numpy ndarray (1-dimensional, float, length incfd*(n - 1) + 1)
Derivative values. d[i*incfd] is the value corresponding to x[i] (i = 0 to n - 1). |
| [in] | a | Lower limit of integration. |
| [in] | b | Upper 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)
Logical variable which should be set to true (1) if the user wishes to skip checks for validity of preceding parameters, or to false (0) otherwise. This will save time in case these checks have already been performed (say, in pchim, pchic, pchsp or pchse). (default = 0) |
- 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
----- -------------
def TestPchia():
n = 7
x = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
y = np.array([0.5, 1, 0.5, 0.2, 0.1, 0.05882, 0.03846])
d = np.empty(n)
print(info)
if info == 0:
a = 0.0
b = 4.0
s, info = pchia(n, x, y, d, a, b)
print(s, info)
def pchia(n, x, f, d, a, b, incfd=1, skip=0) Integral of piecewise cubic Hermite / cubic spline function
def pchse(n, x, f, d, incfd=1) Piecewise cubic spline interpolation ("not a knot" condition)
- Example Results
>>> TestPchia()
0
1.310707380952381 0
|