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

Hi, can someone solve this second part? completely stuck Part 2 - Least Squares

ID: 3707288 • Letter: H

Question

Hi, can someone solve this second part? completely stuck

Part 2 - Least Squares Regression for oceanographic data Create a MATLAB script that does what is outlined below. Save your MATLAB script as LinReg.m and submit your script via canvas Load the .csv file into MATLAB as shown below file - 'C:/Users/Mallory/Dropbox/Laney/Spring 2018/ENGIN 77/fluxes_linreg.csv fileID fopen (file) C textscan (fileID, 'Af %f', 'delimiter', ', ', 'heade r 11 nes', 6); y- 1 } ; %total flux x C(2): %flux per unit width The goal of your code is to find the best fit line using the method of least squares regression Least squares regression takes a set of independent (x) and dependent (y) data points, and creates an estimation function that best fits the data we can solve for ?1 and ?2 using the equation derived in class Where , and y-)% You can assess how well your best fit line fits the data using the coefficient of determination which can be solved using R21-res SStot Where SStot-??1 (yi-vf ? is the average of the given y data) ss,es = ? (yi-9)

Explanation / Answer

y=C{1};
x=C{2};
%paste the below code
X=[x ones(length(x),1)];
beta=(X'*X)X'*y;
alpha1=beta(1);
alpha2=beta(2);
SStot=sum((y-mean(y)).^2);
Y=polyval(beta',x);
SSres=sum((y-Y)).^2;
R2=1-SSres/SStot;
xx=min(x):.01:max(x);
yy=polyval(beta',xx);
plot(x,y,'k.','MarkerSize',10)
hold on
plot(xx,yy,'r','LineWidth',2)
ylabel('flux (m^3/s)')
xlabel('flux/width(m^3/s/m)')
title('Linear Regression for flux vs flux/width')
L=['linear regression (y = ', num2str(alpha1), '*x + ' , num2str(alpha2) ') R^2 = ', num2str(R2)];
legend('actual data',L,'location','northwest')

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