Skip to main content
Engineering LibreTexts

16.5: Higher Order Polynomial Fitting

  • Page ID
    84351
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Let’s try fitting a fifth degree polynomial to the data in example 38.

    Example 9.2.1

    >> x=0:5;y=[12,10,9,6,2,0];
    >> coeffs5=polyfit(x,y,5)

    returns

    coeffs5 =
    -0.0167 0.3333 -2.0833 4.6667 -4.9000 12.0000

    which are the coefficients for the approximating 5th order polynomial, namely
    y = −0.0167x5 + 0.3333x4 − 2.0833x3 + 4.6667x2 − 4.9x + 12.

    We could type out the full polynomial, but there is a shortcut. We can use the function polyval along with linspace to give a smooth approximating curve.

    >> x5=linspace(0,5);
    >> y5=polyval(coeffs5,x5);

    We plot the curves
    >> plot(x,y,’o’,x,besty,x5,y5)

    clipboard_ef7c9c158559418a9daceefdfaf014f47.png


    This page titled 16.5: Higher Order Polynomial Fitting is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Troy Siemers (APEX Calculus) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.