I need help with this problem in MATLAB please! It mentions a previous project d
ID: 3717310 • Letter: I
Question
I need help with this problem in MATLAB please! It mentions a previous project done in C++ so I included my code for that project in here. Thanks!
Problem 2: The data file from Project 4 has been saved as a new MATLAB data file named LinearData.mat". Import this file using the command from Chapter 2 of your textbook. (Do not use the import command!) Your workspace window should show 2 variables: one named x and one named y. Using the equations from Project 4 and built-in MATLAB functions, calculate the slope and y-intercept (do not use loops). Create a y calculated array using the original x values and CMPSC 201 - Spring 2018 Project 5 the slope and y-intercept. Calculate the "Goodness of Fit" using equation from Project 4 (do not use loops). Plot x vs y and x vs ycalculated in the same figure. Use different line types, marks and colors for each plot (refer to Table 4.2)Explanation / Answer
The MATLAB code is given below:
clear;
load('LinearData')
sz = size(x,2);
num = sum(x)*sum(y) - sz*sum(x.*y);
den = sum(x)*sum(x) - sz*sum(x.*x);
slope = num/den;
yinter = (sum(y)-slope*sum(x))/sz;
ycalc = slope*x + yinter;
good = sum(y.*y);
figure;
hold on;
plot(x,y,'--or');
plot(x,ycalc,'-*b');