Make piecewise polynomial - MATLAB mkpp (2024)

Make piecewise polynomial

collapse all in page

Syntax

pp = mkpp(breaks,coefs)

pp = mkpp(breaks,coefs,d)

Description

example

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.

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')

Make piecewise polynomial - MATLAB mkpp (1)

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

1-(x2-1)2=-x24+x.

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

Make piecewise polynomial - MATLAB mkpp (2)

Input Arguments

collapse all

breaksBreak 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

coefsPolynomial 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

dDimension
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.

FieldDescription
form

'pp' for piecewise polynomial

breaks

Vector of length L+1 with strictlyincreasing elements that represent the start and end of each of Lintervals

coefs

L-by-k matrix witheach rowcoefs(i,:)containing the localcoefficients of an orderk polynomial on theithinterval,[breaks(i),breaks(i+1)]

pieces

Number of pieces, L

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

f(x)=a(xx1)3+b(xx1)2+c(xx1)+d.

Extended Capabilities

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.

Make piecewise polynomial - MATLAB mkpp (3)

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)

Asia Pacific

Contact your local office

Make piecewise polynomial - MATLAB mkpp (2024)

FAQs

How do you create a polynomial in MATLAB? ›

p = poly2sym( c ) creates the symbolic polynomial expression p from the vector of coefficients c . The polynomial variable is x . If c = [c1,c2,...,cn] , then p = poly2sym(c) returns c 1 x n − 1 + c 2 x n − 2 + ...

What is ppval in MATLAB? ›

v = ppval( pp , xq ) evaluates the piecewise polynomial pp at the query points xq .

What are piecewise polynomials? ›

A piecewise polynomial of order k with break sequence ξ (necessarily strictly increasing) is, by definition, any function f that, on each of the half-open intervals [ξj ‥ ξj+1), agrees with some polynomial of degree < k. The term 'order' used here is not standard but handy.

What is the Unmkpp function in MATLAB? ›

unmkpp can use a MATLAB pp structure for code generation. To create a MATLAB pp structure from a pp structure created by the code generator: In code generation, use unmkpp to return the piecewise polynomial details to MATLAB. In MATLAB, use mkpp to create the pp structure.

What does Pchip do in MATLAB? ›

p = pchip( x , y , xq ) returns a vector of interpolated values p corresponding to the query points in xq . The values of p are determined by shape-preserving piecewise cubic interpolation of x and y . pp = pchip( x , y ) returns a piecewise polynomial structure for use with ppval and the spline utility unmkpp .

What is the difference between Pchip and spline? ›

The spline second derivative s″(x) is continuous, while the pchip second derivative p″(x) has jumps at the knots. The final pair are the third derivatives. Because both functions are piecewise cubics, their third derivatives, s‴(x) and p‴(x), are piecewise constant.

What is Prim_poly in MATLAB? ›

Description. pr = primpoly(m) returns the primitive polynomial for GF( 2^m ), where m is an integer between 2 and 16 . The Command Window displays the polynomial using " D " as an indeterminate quantity. The output argument pr is an integer whose binary representation indicates the coefficients of the polynomial.

How to write a piecewise function? ›

How do you write piecewise functions? essentially a piece-wise function follows the f(x) = { function domain, notation so for example a function that is x for all values x < 0 and x+1 for all values x >= 0 might be written like f(x) = { x, x < 0; x+1 x >= 0.

Can a piecewise function be continuous? ›

Not all piecewise functions are continuous, but some of them are. A piecewise function can be continuous if: Each function that makes up the piecewise function is continuous. The limits and function values agree at the endpoints of intervals.

Can a piecewise function be differentiable? ›

The answer is sure it can. Assuming that the pieces are differentiable everywhere other than the end points of the pieces, there are two requirements for the endpoints. The function is continuous there. The left and right hand derivatives at that point are equal.

What does dirac mean in MATLAB? ›

dirac returns floating-point results for numeric arguments that are not symbolic objects. dirac acts element-wise on nonscalar inputs. The input arguments x and n must be vectors or matrices of the same size, or else one of them must be a scalar.

What is Polyfit function in MATLAB? ›

polyfit. polyfit(x,y,n) finds the coefficients of a polynomial p(x) of degree n that fits the y data by minimizing the sum of the squares of the deviations of the data from the model (least-squares fit). polyval. polyval(p,x) returns the value of a polynomial of degree n that was determined by polyfit , evaluated at x ...

What is a ramp in MATLAB? ›

Since MATLAB® is a programming language, an endless variety of different signals is possible. Here are some statements that generate a unit impulse, a unit step, a unit ramp, and a unit parabola. t = (-1:0.01:1)'; impulse = t==0; unitstep = t>=0; ramp = t.

What is the poly command in MATLAB? ›

Description. p = poly( r ) , where r is a vector, returns the coefficients of the polynomial whose roots are the elements of r . p = poly( A ) , where A is an n -by- n matrix, returns the n+1 coefficients of the characteristic polynomial of the matrix, det (λI – A).

How to do a polynomial regression in MATLAB? ›

Simple Linear Regression

Fit a first degree polynomial to the data. x = 1:50; y = -0.3*x + 2*randn(1,50); p = polyfit(x,y,1); Evaluate the fitted polynomial p at the points in x . Plot the resulting linear regression model with the data.

References

Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 5688

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.