This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Make piecewise polynomial


pp = mkpp(breaks,coefs)
pp = mkpp(breaks,coefs,d)


pp = mkpp(breaks,coefs) builds a piecewise polynomial, pp, from its breaks and coefficients.

  • breaks is a vector of length L+1 with strictly increasing elements which represent the start and end of each of L intervals.

  • coefs is an L-by-k matrix with each row coefs(i,:) containing the local coefficients of an order k polynomial on the ith interval, [breaks(i),breaks(i+1)]. That is, the polynomial coefs(i,1)*(X-breaks(i))^(k-1) + coefs(i,2)*(X-breaks(i))^(k-2) + ... + coefs(i,k-1)*(X-breaks(i)) + coefs(i,k). Notice that mkpp shifts the polynomial in each interval down by (X-breaks(i)).

pp = mkpp(breaks,coefs,d) indicates that the piecewise polynomial pp is d-vector valued, i.e., the value of each of its coefficients is a vector of length d. breaks is an increasing vector of length L+1. coefs is a d-by-L-by-k array with coefs(r,i,:) containing the k coefficients of the ith polynomial piece of the rth component of the piecewise polynomial.

Use ppval to evaluate the piecewise polynomial at specific points. Use unmkpp to extract details of the piecewise polynomial.

    Note:   The order of a polynomial tells you the number of coefficients used in its description. A kth order polynomial has the form


    It has k coefficients, some of which can be 0, and maximum exponent k – 1. So the order of a polynomial is usually one greater than its degree. For example, a cubic polynomial is of order 4.


collapse all

The first plot shows the quadratic polynomial


shifted to the interval [-8,-4]. The second plot shows its negative


but shifted to the interval [-4,0].

The last plot shows a piecewise polynomial constructed by alternating these two quadratic pieces over four intervals. It also shows its first derivative, which was constructed after breaking the piecewise polynomial apart using unmkpp.

cc = [-1/4 1 0];
pp1 = mkpp([-8 -4],cc);
xx1 = -8:0.1:-4;

pp2 = mkpp([-4 0],-cc);
xx2 = -4:0.1:0;

pp = mkpp([-8 -4 0 4 8],[cc;-cc;cc;-cc]);
xx = -8:0.1:8;
[breaks,coefs,l,k,d] = unmkpp(pp);
dpp = mkpp(breaks,repmat(k-1:-1:1,d*l,1).*coefs(:,1:k-1),d);
hold on, plot(xx,ppval(dpp,xx),'r-'), hold off

See Also

| |

Introduced before R2006a

Was this topic helpful?