You are given four sets of data x and y (eg, x1 and y1, x2 and y2, etc.). You are asked to find a best fit regression line for each of these data sets, and you are told that the relationship between x and y could be linear (y = ao + a1^x), exponential (y = aoe^a1x), a power equation (y = aox^a1.), or a modified Fourier analysis equation (y = ao + a1 cos(x) + a2sin(x2)).
Write a function m-file that:
• receives the vectors x and y as inputs
• uses least squares regression to fit the four models described above. Your code for least squares regression may not use any of MATLAB's built-in regression functions (eg, polyfit), but you may use built-in functions to do common, basic calculations (eg, mean, sum) or to solve linear systems (eg, backslash). Your code must be written to work with any size input data.
• returns as an output the coefficient of determination (R2 ) for all four of the models. Again, you may not use any of MATLAB's built-in regression functions, but you may use built-in functions to do common, basic calculations.
• makes a figure with four plots (ie, using the subplot command), one for each of the four models. The input data points should be shown using a symbol (eg, open circles) and the regression should be plotted as a smooth line.