Required Matlab code with explanatory comments is given below:
function [coeffVec,r2] = Q_myLinReg(xi,yi)
%FINDS THE BEST FIT LINE PARAMETERS AND R-SQUARED VALUE
slope=sum((xi-mean(xi)).*(yi-mean(yi)))/sum(( xi-mean(xi)).^2);
%formula for slope
intercept=mean(yi)-slope*mean(xi); %formula for intercept
coeffVec = [intercept,slope];
r =
sum((xi-mean(xi)).*(yi-mean(yi)))/sqrt(sum((xi-mean(xi)).^2)*sum((yi-mean(yi)).^2));
%r valu
r2=r^2; %r squared value
end
Sample usage:
P2) Write a MATLAB function myLinReg Username that is defined below. Use the in-built MATLAB func...
by using matlab linreg() function file given below On average, the surface area A of human beings is related to weight W and height H. Measurements of several individuals of height 180cm are provided below. It is believed that the following data can be modelled using an exponential equation A = aeBW W (kg) 70 2.1 75 2.12 77 2.15 80 2.20 82 2.22 84 2.23 87 2.26 90 2.30 A (m2) A. Show by hand with pen and paper...
solve part B Note: Do not use MATLAB (or other programming languages) build-in functions for regression. (a) Write a MATLAB (or other programming languages) function that accepts n values of xi and Yi, perform Linear Regression and returns values of rand, the model parameters ao and a. (6) Write another MATLAB (or other programming languages) function that accepts n values of X, and y(provided as arrays), checks for Linear, Power (y = axBx) and Saturation growth- rate (y = a*)...
(Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points with evenly spaced nodes from x1 = a to xm = b, and values from f(x); • location z satisfying x2 < z < xm−1, where h = (b − a)/(m − 1); and outputs the value of the interpolaton polynomial using only...
MATLAB Code for question (2) 1) Use the Matlab function polyfit to curve fit the saturation pressure versus temperature data along the vaporization line for water in the table below with a polynomial of degree n. The Matlab function polyval may be used to evaluate the polynomial at any point. Compare the saturation pressure as calculated by the polynomial with the data given in the table and observe what happens as the degree of the polynomial n is increased. Tabulate...
A group of physics students collected data from a test of the projectile motion problem that was analyzed in a previous lab exercise (L5). In their test, the students varied the angle and initial velocity Vo at which the projectile was launched, and then measured the resulting time of flight (tright). Note that tright was the dependent variable, while and Vo were independent variables. The results are listed below. (degrees) Time of Flight (s) Initial Velocity V. (m/s) 15 20...