Question: I need help writing the MATLAB code. Please help or advise for each part of the question. I ONLY need help with PART 2 The
I need help writing the MATLAB code. Please help or advise for each part of the question. I ONLY need help with PART 2 The MATLAB academy is referring to is "Introduction to Statistical Methods with MATLAB". Ch 3.1 (Linear regression)\ \ PART 1\ \ \ A temperature sensor measures temperature (T) by producing an output voltage (V). A number of experimental (T,V)\ pairs are recorded in the Excel file named M5data.xlsx, one pair per row. You can download the file to see what it looks like and to work offline if you need to, but in your solution just refer to it as "M5data.xlsx".\ \ \ 1. Use the readmatrix() function to load the experimental data into a temporary matrix with 2\ columns. Then extract the first column into a vector T and the second column into a vector V.\ 2. Create a scatter plot by plotting T on the horizontal axis and V on the vertical axis. Use markers\ but no lines between points. Label both axes appropriately. The units are degrees Fahrenheit and Volts.\ 3. Perform a linear regression analysis of the two variables (T and V), that is, compute the intercept\ a and slope b as described in the textbook. Display the values of a and b.\ \ \ Notes:\ ** You have to write your own code to compute the parameters a and b, you cannot use MATLAB functions\ other than sum().\ **The Matlab Academy course uses a different notation for the regression line (y=ax+b) than the one used in the\ textbook (y=a+bx).\ \ \ PART 2\ A temperature sensor measures temperature (T) by producing an output voltage (V). A number of experimental (T,V)\ pairs are recorded in the attached Excel file M5data.xlsx, one pair per row.\ 1. Use the readmatrix() function to load the experimental data into a temporary matrix with 2\ columns. Then extract the first column into a vector T and the second column into a vector V.\ 2. Find a linear model for the relationship between T and V (i.e. V as a function of T) using the\ fit() function. Call the model object "linfit". Display the slope and intercept. For your own sake,\ compare these values to the ones you calculated in M5.2.\ 3. Plot the linear relationship as you learned in the Matlab Academy course. Label both axes\ appropriately. The units are degrees Fahrenheit and Volts.\ 4. Find a quadratic model for the relationship between T and V (i.e. V as a function of T) using the\ fit() function. Call the model object "sqfit". Display the model coefficients using the\ coeffvalues() function.\ \ 5. Plot the quadratic relationship as you learned in the Matlab Academy course. Label both axes\ appropriately. The units are degrees Fahrenheit and Volts.\ \ Notes:\ ** The Matlab Academy course uses a different notation for the regression line (y=ax+b) than the one used\ in the textbook (y=a+bx).\ \ PART 1 code:\ \ \ 1.\ Mat=readmatrix("M5data.xlsx");\ T=Mat(:,1);\ V=Mat(:,2);\ \ 2.\ plot(T,V,'*')\ xlabel('degrees Fahrenheit')\ ylabel('Volts')\ \ 3.\ avg_t=sum(T)/length(T);\ avg_v=sum(V)/length(V);\ \ SStt = (avg_t-T).^2;\ SStv = (avg_t-T).*(avg_v-V);\ \ b = sum(SStv)/sum(SStt)\ %intercept\ a = avg_v - b*avg_t\ \ \ \ \ M5data.xlsx\ \ Te Ve\ 82.1 5.8\ 77 5.7\ 39.4 3.5\ 79.6 5\ 53.2 4.6\ 71.7 5.3\ 41.6 2.9\ 73.3 5.3\ 50.7 3.8\ 63.2 4.9\ 58.8 4.9\ 99.1 5.8\ 62.4 5.3\ 59 4.7\ 41.4 3.3\ 52.9 3.2\ 109.2 6\ 94.1 6.2\ 46.1 3.9\ 93.4 5.3\ 82.8 5.2\ 92 5.8\ 49.6 3.7\ 103.4 5.7\ 103.5 5.4\ 76.5 5.3\ 73.4 5.2\ 61.8 5\ 53.5 3.8\ 65.2 5\ 38.4 2.6\ 45.8 3.8\ 36.1 3.3\ 109.8 5.5\ 79.6 5.9\ 58.5 5.1\ 97.8 6.8\ 43.4 3.2\ 33.3 2.2\ 50.4 3.9\ 46.2 4.2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
