Make piecewise polynomial
collapse all in page
Syntax
pp = mkpp(breaks,coefs)
pp = mkpp(breaks,coefs,d)
Description
pp = mkpp(breaks,coefs)
buildsa piecewise polynomial pp
from its breaks and coefficients.Use ppval to evaluate the piecewisepolynomial at specific points, or unmkpp toextract details about the piecewise polynomial.
example
pp = mkpp(breaks,coefs,d)
specifiesthat the piecewise polynomial is vector-valued, such that the valueof each of its coefficients is a vector of length d
.
Examples
collapse all
Create Piecewise Polynomial with Polynomials of Several Degrees
Open Live Script
Create a piecewise polynomial that has a cubic polynomial in the interval [0,4], a quadratic polynomial in the interval [4,10], and a quartic polynomial in the interval [10,15].
breaks = [0 4 10 15];coefs = [0 1 -1 1 1; 0 0 1 -2 53; -1 6 1 4 77];pp = mkpp(breaks,coefs)
pp = struct with fields: form: 'pp' breaks: [0 4 10 15] coefs: [3x5 double] pieces: 3 order: 5 dim: 1
Evaluate the piecewise polynomial at many points in the interval [0,15] and plot the results. Plot vertical dashed lines at the break points where the polynomials meet.
xq = 0:0.01:15;plot(xq,ppval(pp,xq))line([4 4],ylim,'LineStyle','--','Color','k')line([10 10],ylim,'LineStyle','--','Color','k')
Create Piecewise Polynomial with Repeated Pieces
Open Live Script
Create and plot a piecewise polynomial with four intervals that alternate between two quadratic polynomials.
The first two subplots show a quadratic polynomial and its negation shifted to the intervals [-8,-4] and [-4,0]. The polynomial is
The third subplot shows a piecewise polynomial constructed by alternating these two quadratic pieces over four intervals. Vertical lines are added to show the points where the polynomials meet.
subplot(2,2,1)cc = [-1/4 1 0]; pp1 = mkpp([-8 -4],cc);xx1 = -8:0.1:-4; plot(xx1,ppval(pp1,xx1),'k-')subplot(2,2,2)pp2 = mkpp([-4 0],-cc);xx2 = -4:0.1:0; plot(xx2,ppval(pp2,xx2),'k-')subplot(2,1,2)pp = mkpp([-8 -4 0 4 8],[cc;-cc;cc;-cc]);xx = -8:0.1:8;plot(xx,ppval(pp,xx),'k-')hold online([-4 -4],ylim,'LineStyle','--')line([0 0],ylim,'LineStyle','--')line([4 4],ylim,'LineStyle','--')hold off
Input Arguments
collapse all
breaks
— Break points
vector
Break points, specified as a vector of length L+1
withstrictly increasing elements that represent the start and end of eachof L
intervals.
Data Types: single
| double
coefs
— Polynomial coefficients
matrix
Polynomial coefficients, specified as an L
-by-k
matrixwith the ith row coefs(i,:)
containing the localcoefficients of an order k
polynomial on the ithinterval, [breaks(i), breaks(i+1)]
. In other words,the polynomial is 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)
.
Data Types: single
| double
d
— Dimension
scalar | vector
Dimension, specified as a scalar or vector of integers. Specify d
tosignify that the piecewise polynomial has coefficient values of size d
.
Data Types: single
| double
Output Arguments
collapse all
pp
— Piecewise polynomial
structure
Piecewise polynomial, returned as a structure. Use this structurewith the ppval function toevaluate the piecewise polynomial at one or more query points. Thestructure has these fields.
Field | Description |
---|---|
form |
|
breaks | Vector of length |
coefs |
|
pieces | Number of pieces, |
order | Order of the polynomials |
dim | Dimensionality of target |
Since the polynomial coefficients in coefs
arelocal coefficients for each interval, you must subtract the lowerendpoint of the corresponding knot interval to use the coefficientsin a conventional polynomial equation. In other words, for the coefficients [a,b,c,d]
onthe interval [x1,x2]
, the corresponding polynomialis
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The output structure
pp
differsfrom thepp
structure in MATLAB®. In MATLAB,ppval
cannotuse thepp
structure from the code generator. Forcode generation,ppval
cannot use app
structurecreated by MATLAB.unmkpp
can use a MATLABpp
structurefor code generation.To create a MATLAB
pp
structure fromapp
structure created by the code generator:In code generation, use
unmkpp
toreturn the piecewise polynomial details to MATLAB.In MATLAB, use
mkpp
to createthepp
structure.
If you do not provide
d
, thencoefs
mustbe two-dimensional and have a fixed number of columns. In this case,the number of columns is the order.To define a piecewise constant polynomial,
coefs
mustbe a column vector ord
must have at least twoelements.If you provide
d
andd
is1
,thend
must be a constant. Otherwise, if the inputtoppval
is nonscalar, then the shape of theoutput ofppval
can differ fromppval
in MATLAB.If you provide
d
, then it musthave a fixed length. One of the following sets of statements mustbe true:Suppose that
m = length(d)
andnpieces= length(breaks) - 1
.size(coefs,j) = d(j) size(coefs,m+1) = npiecessize(coefs,m+2) = order
j
= 1,2,...,m.The dimensionm+2
must be fixed length.Suppose that
m = length(d)
andnpieces= length(breaks) - 1
.The second dimensionmust be fixed length.size(coefs,1) = prod(d)*npiecessize(coefs,2) = order
If you do not provide
d
, then thefollowing statements must be true:Suppose that
m = length(d)
andnpieces= length(breaks) - 1
.The second dimension must befixed length.size(coefs,1) = prod(d)*npiecessize(coefs,2) = order
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a
See Also
ppval | spline | pchip | unmkpp
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office