Part 1.2 - Testing your pnfit function
Write a script m-file, called test_pnfit_xxxx, to test pnfit_xxxx. This m-file should:
1. Prompt the user to supply 'n', the x-axis label, the y-axis label, and the plot title.
2. Generate the 'x' and 'y' vectors using polyval() as indicated below.
3. Call the function pnfit xxxx to determine the polynomial coefficients and the corresponding
square error. Display both.
4. Generate a single plot containing
• the experimental data points (x, y), with X's for data markers, and no connecting line, and
• a smooth plot of $\hat{y}$, the least-squares fit to the data, over the range of x-values represented in
the experiment. Use a blue line with thickness of 3.
In this file, define a given test vector x, and use polyval to generate data vectors y for 2 known
polynomials (of your choice):
• a 2nd degree polynomial, say P2; call the data vectors x2_test and y2_test; and
• a 4th degree polynomial, say P4; call the data vectors x4_test and y4_test.
Use trial and error to choose a reasonable range of x values for P2 and P4, to ensure that you've
covered the "interesting" regions (where the polynomial may change directions).
Keep debugging your code until you can obtain the correct least-squares fit for both test cases.