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

You will write a function that performs least-squares linear regression on any f

ID: 3863592 • Letter: Y

Question

You will write a function that performs least-squares linear regression on any function of the form. where: _The ai's are the coercions to be determined using least-squares linear regression. _The if's are real-valued functions. _The if's are linearly independent of each other. More precisely, write a function with the following header: function [coefficients, e2] = my regression genic (x_data, y_data, f) where: x_data and y_data are two m _ 1 arrays of class double that represent two-dimensional data. in other words, these column vectors represent a set of points of coordinates (x_data(i); y_data(i)), i = f1; 2;:::;mg. You can assume that m > 1, and that all elements of x_data and y_data are different from NaN, Inf, and -Inf. _ f is a 1 _ n cell array that contains function handles that represent the fi's of Equation 3 (f {i} represents fi). Each of these function handles takes a single input argument that is an array of class double of any size (and whose elements are different from NaN, Inf, and -Inf), and outputs a single output argument that is an array of class double of the same size as the input array (and whose elements are also different from NaN, Inf, and -Inf). You can assume that n > 0. _ coefficients is a n_l array of class double that represents the ai's of Equation 3 (a (1) represents ai), fitted to the x- and y-data represented by x_data and y_data (respectively), using least-squares linear regression. _ e2 is the square error associated with the linear regression performed by the function. Test cases: >> % Load the sample data >> Ioad('lab09_sample_data.mat); >> % Data set q2_xl and q2_yl (fit a straight line) >> f = {@(x) x, @(x) ones(size(x))}; >> (coefficients, e2] = my_regression_generic(q2_xl, q2_yl, f) coefficients = -13.2333 -9.1484 e^2 = 4

Explanation / Answer

Code :

function [coefficient e2]=my_regression_generic(q2_x1,q2_y1,f)

[fit1,gof,fitinfo] = fit(q2_x1,q2_y1,f,'StartPoint',[1 1]);

coefficient=fit1;

e2=fitinfo;

end

Output :

Output is not provided because the input data is not available.

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