0

I do not understand number two:

The value of the polynomial spline function for an argument x is computed as follows:

  1. The knot array is searched to find the segment to which x belongs. If x is less than the smallest knot point or greater than the largest one, an IllegalArgumentException is thrown.
  2. Let j be the index of the largest knot point that is less than or equal to x. The value returned is polynomials[j](x - knot[j])

The polynomial array is always one value less than the knot array right? So the second section does not always work? Is there a better way to state number 2?

Link to documentation

smuggledPancakes
  • 9,881
  • 20
  • 74
  • 113

1 Answers1

1

That just says that if x belongs to the interval [knot[j], knot[j+1]], then the corresponding y value will be computed as polynomials[j](x - knot[j]). If your polynomials array's last index is n then the last knot interval will be [knot[n], knot[n+1]], meaning the last index of the knot array is n+1 (so 2 will always hold).

SamYonnou
  • 2,068
  • 1
  • 19
  • 23
  • So is the explanation that I got from the Apache docs just very terse? Am I correct in saying that you had to infer your answer? – smuggledPancakes Aug 20 '13 at 20:29
  • 1
    I wouldn't say that, but their explanation is definitely like something you might read in a math textbook. They say that `j` is index of the largest knot less than or equal to `x` which is equivalent to saying that `knot[j]` is the left endpoint of the interval `x` falls into. If `knot[j]` is the left endpoint then it follows that `knot[j+1]` must be the right endpoint. This in turn means that the only way that `polynomials[j]` will produce and `ArrayIndexOutOfBounds` is if `knot[j+1]` does not exist (i.e., `j` is the last index of `knot`) but this is already taken care of by (1). – SamYonnou Aug 20 '13 at 20:41