# Fit a polynomial of optimal degree to these points:

Fit a polynomial of optimal degree to these points:

s 1.1 1.6 11.4 4.1 5.3 17.5 9.4 11.5 12.1

f(x) 7.9 24.8 -28.8 42.6 29.6 -34.6 -3.1 -28.7 -39.6

Use "polyfit" function using MATLAB.

See the attached file.

Â© BrainMass Inc. brainmass.com December 24, 2021, 6:32 pm ad1c9bdddfhttps://brainmass.com/math/basic-algebra/fit-polynomial-optimal-degree-120432

## SOLUTION This solution is **FREE** courtesy of BrainMass!

Please see the attached file.

6)

Fit a polynomial of optimal degree to these points:

s 1.1 1.6 11.4 4.1 5.3 17.5 9.4 11.5 12.1

f(x) 7.9 24.8 -28.8 42.6 29.6 -34.6 -3.1 -28.7 -39.6

Use "polyfit" function using MATLAB.

First if you'd like help with polyfit in Matlab, type at the command prompt:

> help polyfit

Note that the code for polyfit is

POLYFIT(X,Y,N) with x and y being the array of data need to be defined and n being the order of your polynomial. In this program i'm using n=3 but you should try with other n values so that you can compare the fits.

At the prompt, using these commands to enter the values of x and y:

> x=[1.1 1.6 11.4 4.1 5.3 17.5 9.4 11.5 12.1]

> y=[7.9 24.8 -28.8 42.6 29.6 -34.6 -3.1 -28.7 -39.6]

polyfit makes the computation of the coefficients easy. The tough part of polynomial regression is knowing that the "fit" is a good one. Determining the quality of the fit requires experience, a sense of balance and some statistical summaries.

Does the fit look good?

A picture is worth a thousand words and so a plot of the curve that represents the fitted polynomial overlaid on the data is a powerful way of assessing the quality of the fit. Using the coefficients determined by polyfit, you can create such a plot via the commands

> coeff = polyfit(x,y,3)

> xfit = linspace(min(x),max(x),100);

> yfit = polyval(coeff,xfit);

> plot(x,y,'o',xfit,yfit)

And it should show you a nice plot

Reference:

http://www.facstaff.bucknell.edu/maneval/help211/fitting.html.

https://brainmass.com/math/basic-algebra/fit-polynomial-optimal-degree-120432