Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MATLAB Please do not use any tools that do not come in the basic student MATLAB package Write a function [slope, R2] = mySlope Finder
MATLAB
Please do not use any tools that do not come in the basic student MATLAB package
Write a function [slope, R2] = mySlope Finder (XData,yData) to perform least-squares linear regression to find best-fit slope with the y-intercept equal to zero. In addition to the slope, your function should also calculate and return the regression statistics R2. The inputs to the function mySlopeFinder are xData (1 xn or n x 1 double) and yData ( x nor n x 1 double), while the outputs are slope (1 x 1 double), R2 (1 x 1 double). Note: MATLAB's built-in polyfit function should not be used for this problem, as there is no way with polyfit to force the intercept to be zero. Review the associated lecture slides to find the formulas to calculate the least-squares linear regression, the coefficient of determination (R2) TEST CASE 1 >x1:10; >> y = 0.5 + 0.95*x; >> [slope, R2] = myslope Finder (x,y) slope = 1.0214 R2 = 0.9928 Write a function [slope, R2] = mySlope Finder (XData,yData) to perform least-squares linear regression to find best-fit slope with the y-intercept equal to zero. In addition to the slope, your function should also calculate and return the regression statistics R2. The inputs to the function mySlopeFinder are xData (1 xn or n x 1 double) and yData ( x nor n x 1 double), while the outputs are slope (1 x 1 double), R2 (1 x 1 double). Note: MATLAB's built-in polyfit function should not be used for this problem, as there is no way with polyfit to force the intercept to be zero. Review the associated lecture slides to find the formulas to calculate the least-squares linear regression, the coefficient of determination (R2) TEST CASE 1 >x1:10; >> y = 0.5 + 0.95*x; >> [slope, R2] = myslope Finder (x,y) slope = 1.0214 R2 = 0.9928Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started