If I do the following in MATLAB:
ppval(mkpp(1:2, [1 0 0 0]),1.5)
ans = 0.12500
This should construct a polynomial f(x) = x^3 and evaluate it at x = 1.5. So why does it give me the result 1.5^3 = .125? Now, if I change the domain defined in the first argument to mkpp, I get this:
> ppval(mkpp([1 1.5 2], [[1 0 0 0]; [1 0 0 0]]), 1.5)
ans = 0
So without changing the function, I change the answer. Awesome.
Can anyone explain what’s going on here? How does changing the first argument to mkpp change the result I get?
The function MKPP will shift the polynomial so that
x = 0will start at the beginning of the corresponding range you give it. In your first example, the polynomialx^3is shifted to the range[1 2], so if you want to evaluate the polynomial at an unshifted range of[0 1], you would have to do the following:In your second example, you have one polynomial
x^3shifted to the range[1 1.5]and another polynomialx^3shifted to the range of[1.5 2]. Evaluating the piecewise polynomial atx = 1.5gives you a value of zero, occurring at the start of the second polynomial.It may help to visualize the polynomials you are making as follows: