Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In determining the best fit polynomial approximating curve to the (H vs. Q) data

ID: 3820861 • Letter: I

Question

In determining the best fit polynomial approximating curve to the (H vs. Q) data obtained from a pump manufacturer's catalog (units changed to SI units). The data points of the CH vs. Q) curve are shown in Table P8.2 Try degree polynomials of 2 through 4 to determine which degree polynomial will give the smallest mse. Use MATLAB's function polyfit, which returns the coefficients for each of the three polynomials. Then use MATLAB's function polyval to create for each polynomial: a) A table containing Q, H_C, and H_C where HC is the approximating curve for H VS.Q. (b) A plot of H_C VS. Q (solid line) and H vs. Q (small circles, all plots on the same page.

Explanation / Answer

Matlab has two functions, polyfit and polyval, using which we can easily fit a set of data points with a polynomial.

Polyfit: This function is used in finding the coefficients of a polynomial p(x) of degree n that best fits with the given data.

polyfit(x,y,n)   

Polyval: This function is used to evaluate the value of the polynomial ie ir returns the value of f(x) at a given value of x.

polyval(p,x)

Plot : We can plot the graph using plot(x,y) function.

To get the best fit, we evaluate the polynomial at the data points and generate a table showing the data, fit and errors as follows:

f=polyval(p,x);

T=table(x,y,f,y-f,'VariableNames', { 'X', 'Y', 'Fit', 'FitError'})

For the given data

x=[3.3 6.9 13.7 20.5 27.4 34.2 41.1 61.6 68.5 75.3]

y=[43.3 43.4 43.6 43.6 43.3 43.0 42.7 40.8 39.6 38.7 37.2 36.3 34.4 32.6]

% coefficients at degree 2 %

a= polyfit(x,y,2) ;

% coefficients at degree 3 %

b= polyfit(x,y,3);

% coefficients at degree 4 %

c=polyfit(x,y,4);

x1=0:3.3:6.9;

y1=polyval(a,x1);

y2=polyval(b,x1);

y3=polyval(c,x1);

T=table (x1,y1,y2, 'VariableNames', {'Q', 'Hc','H'})

plot(x1,y1,y2);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote