Solved: (Least Squares Fit to a Data Set by a Linear Function) The following table of x

Chapter 5, Problem 3

(choose chapter or problem)

(Least Squares Fit to a Data Set by a Linear Function) The following table of x and y values was given in Section 5.3 of this chapter (see Figure 5.3.3). x 1.0 0.0 2.1 2.3 2.4 5.3 6.0 6.5 8.0 y 1.02 0.52 0.55 0.70 0.70 2.13 2.52 2.82 3.54 The nine data points are nearly linear and hence the data can be approximated by a linear function z = c1x + c2. Enter the x and y coordinates of the data points as column vectors x and y, respectively. Set V = [ x, ones(size(x))] and use the MATLAB \ operation to compute the coefficients c1 and c2 as the least squares solution to the 9 2 linear system Vc = y. To see the results graphically, set w = 1 : 0.1 : 8 and z = c(1) w + c(2) ones(size(w)) and plot the original data points and the least squares linear fit, using the MATLAB command plot(x, y, x, w, z)function c1x + c2, set up an overdetermined systemVc = T. The coefficient matrix V can begenerated in MATLAB by settingV = [ p, ones(10, 1)]or, alternatively, by settingA = vander(p); V = A(:, 9 : 10)Note For any vector x = (x1, x2, ... , xn+1)T ,the MATLAB command vander(x) generatesa full Vandermonde matrix of the formxn1 xn11 x1 1xn2 xn12 x2 1...xnn+1 xn1n+1 xn+1 1For a linear fit, only the last two columns ofthe full Vandermonde matrix are used. Moreinformation on the vander function can beobtained by typing help vander. Once Vhas been constructed, the least squares solutionc of the system can be calculated using theMATLAB \ operation.(b) To see how well the linear function fits the data,define a range of pressure values by settingq = 1 : 0.1 : 10;The corresponding function values can be determinedby settingz = polyval(c, q);We can plot the function and the data points withthe commandplot(q, z, p, T, x)(c) Let us now try to obtain a better fit by usinga cubic polynomial approximation. Againwe can calculate the coefficients of the cubicpolynomialc1x3 + c2x2 + c3x + c4that gives the best least squares fit to the databy finding the least squares solution of an overdeterminedsystem Vc = T. The coefficientmatrix V is determined by taking the last fourcolumns of the matrix A = vander(p). To seethe results graphically, again setz = polyval(c, q)and plot the cubic function and data points, usingthe same plot command as before. Where doyou get the better fit, at the top or bottom of theatmosphere?(d) To obtain a good fit at both the top and bottomof the atmosphere, try using a sixth-degreepolynomial. Determine the coefficients as beforeusing the last seven columns of A. Set z =polyval(c, q) and plot the results

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back