Question: ,MatLAB CODE Write a user-defined MATLAB function that determines the equation of the least squares regression line passing through given data points. For function name

 ,MatLAB CODE Write a user-defined MATLAB function that determines the equation

,MatLAB CODE

Write a user-defined MATLAB function that determines the equation of the least squares regression line passing through given data points. For function name and arguments, use [m, b] = myline(x, y) The input arguments x and y are the vectors containing the data points and the output arguments m and b are the slope and intercept of the regression line, respectively. Test your function for the following input and see if it returns the correct answer ( 1.2662, b - -2.6478) x = [0.2, 0.5, 0.9, 1.6, 2.5, 2.8, 4.1]; y= [-2.38,-1.87,-1.76,-0.53, 0.58, 0.82, 2.56]; [m, b] = myline(x,y) Note 1: Perform sanity check in the beginning of your user-defined function to make sure that x and y are both vectors, and they have the same size (same # of rows and same # of columns). Note 2: The equation of the least squares regression line y = mz + b that passes through data points x and y is given by: Note 3: You are NOT allowed to use built-in function polyfit to calculate m and b. Calculations should be done based on given equations and using simple operators and commands in MATLAB. For example XiYi = sum ,2.xy

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!