12.3: Polynomials in MATLAB

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    12.3: Polynomials in MATLAB

    A polynomial is a mathematical expression made from powers of a variable multiplied by coefficients. In one variable, a polynomial can look like this:

    \(p(x) = a_n*x^n + a_(n-1)*x^(n-1) + ... + a_1*x + a_0\)

    The highest power of x is called the degree, or order, of the polynomial. A first-order polynomial is a straight line, a second-order polynomial is a quadratic, and a third-order polynomial is a cubic.

    Polynomial Type

    Degree

    General Form

    Line

    1

    \(a*x + b\)

    Quadratic

    2

    \(a*x^2 + b*x + c\)

    Cubic

    3

    \(a*x^3 + b*x^2 + c*x + d\)

    Representing a Polynomial as a Vector

    In MATLAB, a polynomial is represented as a row vector of coefficients. The coefficients are listed from the highest power down to the constant term. This is a very important convention.

    For example, the polynomial

    \(x^3 + 2*x^2 - 4*x + 3\)

    is represented in MATLAB as:

    p = [1 2 -4 3];

    The first number, 1, is the coefficient of \(x^3\). The second number, 2, is the coefficient of \(x^2\). The third number, -4, is the coefficient of \(x\), and the last number, 3, is the constant term.

    Caution

    Always include zero coefficients for missing powers. MATLAB determines the degree of the polynomial from the length of the coefficient vector.

    For example, the polynomial

    \(2*x^5 - x^2 + 5\)

    must be represented as:

    p = [2 0 0 -1 0 5];

    The zeros are placeholders for \(x^4\), \(x^3\), and \(x\). Without those zeros, MATLAB would interpret the polynomial incorrectly.


    This page titled 12.3: Polynomials in MATLAB was last modified on Tue, 30 Jun 2026 02:11:51 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.