Question: Write a MATLAB function myfit that will be called from the command line like this: [coef, new_y, error_y] = myfit (X_list, Y_list) The function should

Write a MATLAB function myfit that will be called from the command line like this: [coef, new_y, error_y] = myfit (X_list, Y_list) The function should use polyfit to determine the best fit curve for the points in X_list and Y_list. The degree of the polynomial should be the smallest degree polynomial with an average error (the average value of the absolute value of the difference between the new y-coordinates and the original y-coordinates) less than 1. You function should return three outputs in the following order

the vector of coefficients of the polynomial

the vector of the new y-coordinates which is the polynomial evaluated at the original x-coordinates

the vector of the error magnitudes (absolute value) of the y-coordinates

Example Test Case:

X_list = [ 1, 3, 5, 7, 9] ; Y_list = [ 4.1054, 3.7485, 5.4772, 9.036, 15.68 ]; [coef,new_y,error_y]=myfit(X_list, Y_list) 

Should display this result in the command window

coef = 0.2827 -1.4053 5.3064 new_y = 4.1838 3.6349 5.3477 9.3222 15.5585 error_y = 0.0784 0.1136 0.1295 0.2862 0.1215 

Your code should work for any set of starting values. Do not include test cases, clear all, etc as part of your submission.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!