Question: MATLAB Write a function (using the function keyword) that: - Accepts two vectors (x) and (y) as input. We will later call this function with

MATLAB
MATLAB Write a function (using the function keyword) that: - Accepts two
vectors (x) and (y) as input. We will later call this function

Write a function (using the function keyword) that: - Accepts two vectors (x) and (y) as input. We will later call this function with x representing height and y representing weight. - Calculates the the slope (b) and intercept ( a ) of the regression line (i.e., the best fitting line through the points defined by x,y coordinates) according to equations below - Calculates the correlation coefficient ( r ) for the two variables according to equation below. Do not use the built-in Matlab function for correlation (but note that you could check your code by comparing your results with Matlab's correlation function) - Returns the values of a,b, and r to the main program - Complete the calculations with matrix algebra - not loops. - Take special care to use element-wise operations (e.g. . and .^) For a regression line, we have: y=a+bx Where the slope (b), intercept (a) of the regression line can be calculated as: b=ni=1nxi2(i=1nxi)2ni=1nxiyi(i=1nxi)(i=1nyi)a=ni=1nyibni=1nxi Note that n represents the number of observations and the capital sigma represents summation (if you have never seen this notation, read this wiki page b). The correlation coefficient (r) can be calculated as follows: r=[(n2n)()n)2[(nn)()2]ni=1nxiyi(i=1nxi)(i=1nyi) Note that n represents the number of observations and the capital sigma represents summation (if you have never seen this notation, read this wikipage G ). The correlation coefficient ( r ) can be calculated as follows: r=[(ni=1nxi2)(i=1nxi)2][(ni=1nyi2)(i=1nyi)2]ni=1nxiyi(i=1nxi)(i=1nyi) To reduce error in converting these equations to Matlab, try to avoid having one long equation on one line. It helps to break the equations (especially the equation for r ) into smaller equations and save these to temporary variables. Hint: many of the calculations in these formulas imply "elementby-element" multiplication or raising each individual element of a vector to some power. There is specific Matlab notation you have to use to force the element-by-element computation

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!