In MATLAB, please
Basic Least-Squares Regression solutions submitted (max: Unlimited)
Sample data is contained in the "SampleData.xlsx" spreadsheet on Canvas. Load in the data using readmatrix().
2) Use fit() and any necessary post-processing commands to fit a 1st order polynomial in the form of:
au + a
to the data.
Compute R^2 (there are many hard ways and one easy way).
Use the regression line to predict Y given a random X-value of 5.
Generate a well-labeled plot of the data (including Y vs. X) and the best-fit line in your function.
Do not use polyfit() or polyval().
NOTE: You need to have the Curve Fitting Toolbox installed on your local MATLAB. If you don't know if you have it or not, please check.
Function
function [a1, a2, R2, Y_fit] = LinearRegression(x_eval)
Input x_eval: value of X for which to evaluate the curve (scalar)
Outputs:
a1: Slope of the best straight line through the data (ND)
a2: Y-intercept of the best straight line through the data (scalar)
R2: Coefficient of determination of the data (ND)
Y_fit: Fitted value for x_eval value (scalar)
Write your code below: