The function MKPP will shift the polynomial so that x = 0
will start at the beginning of the corresponding range you give it. In your first example, the polynomial x^3
is 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:
>> pp = mkpp(1:2,[1 0 0 0]); %# Your polynomial
>> ppval(pp,1.5+pp.breaks(1)) %# Shift evaluation point by the range start
ans =
3.3750 %# The answer you expect
In your second example, you have one polynomial x^3
shifted to the range [1 1.5]
and another polynomial x^3
shifted to the range of [1.5 2]
. Evaluating the piecewise polynomial at x = 1.5
gives 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:
x = linspace(0,3,100); %# A vector of x values
pp1 = mkpp([1 2],[1 0 0 0]); %# Your first piecewise polynomial
pp2 = mkpp([1 1.5 2],[1 0 0 0; 1 0 0 0]); %# Your second piecewise polynomial
subplot(1,2,1); %# Make a subplot
plot(x,ppval(pp1,x)); %# Evaluate and plot pp1 at all x
title('First Example'); %# Add a title
subplot(1,2,2); %# Make another subplot
plot(x,ppval(pp2,x)); %# Evaluate and plot pp2 at all x
axis([0 3 -1 8]) %# Adjust the axes ranges
title('Second Example'); %# Add a title
