Lab5 - MatLab Lab Assignment 5 Exercises 1 Exercise 1 a Having an even distribution of data points both greater than and less than zero I would expect

Lab5 - MatLab Lab Assignment 5 Exercises 1 Exercise 1 a...

This preview shows page 1 - 5 out of 5 pages.

MatLab Lab Assignment 5 Exercises: 1) Exercise 1 a. Having an even distribution of data points both greater than and less than zero, I would expect the best-fit line to be near perfectly horizontal. b. Generated data clf format short e x = [1:1:100]'; y = randn(size(x)); X = [ones(size(x)),x]; z = X'*y; S = X'*X; U = chol(S); w = U'\z; c = U\w plot(x,y, '.' ) q = x; fit = c(1)+c(2)*q; hold on plot(q,fit, 'r' ); i) Slope and y-intercept
Image of page 1

Subscribe to view the full document.

c = -5.4989e-02 1.1098e-03 ii) The values closely match what I had expected, very near horizontal. 2) Exercise 2 a. Linear Plot clf format short e dat = load('co2.dat'); year = dat(:,1); conc= dat(:,2); X = [ones(size(year)),year]; z = X'*conc; S = X'*X; U = chol(S); w = U'\z; c = U\w plot(year,conc,'o') q = year; fit = c(1)+c(2)*q; hold on axis tight plot(q,fit,'black', 'linewidth', 2); b. Quadratic Plot Added to Original c = -2.5955e+03 -c1 1.4830e+00 -c2
Image of page 2
clf format short e dat = load( 'co2.dat' ); year = dat(:,1); conc= dat(:,2); %part a) X = [ones(size(year)),year]; z = X'*conc; S = X'*X; U = chol(S); w = U'\z; c = U\w plot(year,conc, 'o' ) q = year; fit = c(1)+c(2)*q; hold on plot(q,fit, 'black' , 'linewidth' , 2); axis tight %part b) X = [ones(size(year)),year,year.^2]; z = X'*conc; S = X'*X; U = chol(S); w = U'\z; c = U\w q = year; fit = c(1)+c(2)*q+c(3)*q.^2;
Image of page 3

Subscribe to view the full document.

Image of page 4
Image of page 5

Unformatted text preview: hold on plot(q,fit, 'r' , 'linewidth' , 2); axis tight legend( 'data points' , 'linear fit' , 'quadratic fit' , 'Location' , 'Northwest' ) 3) Exercise 3 a. Cubic fit c = 4.4149e+04-c1 4.5606e+01-c2 1.1858e-02-c3 clf format short e x =[1:10]'; y= [222;227;223;233;244;253;260;266;270;266]; X = [ones(size(x)),x,x.^2,x.^3]; z = X'*y; S = X'*X; U = chol(S); w = U'\z; c = U\w plot(x,y, 'o' ) q = 0:0.1:11; fit = c(1)+c(2)*q+c(3)*q.^2+c(4)*q.^3; hold on plot(q,fit, 'r' , 'linewidth' , 1); legend( 'data points' , 'cubic fit' , 'Location' , 'Northwest' ) b. Plot Method Change clf format short e x =[1:10]'; y= [222;227;223;233;244;253;260;266;270;266]; plot(x,y, 'o' ) X = [ones(size(x)),x,x.^2,x.^3]; c = X\y c = c([4:-1:1]); c = 2.3023e+02-c1-1.0309e+01-c2 3.7302e+00-c3-2.3388e-01-c4 c = 2.3023e+02-c1-1.0309e+01-c2 3.7302e+00-c3-2.3388e-01-c4 q = 1:0.1:10; z = polyval(c,q); figure plot(q,z,x,y, 'o' ); legend( 'data points' , 'cubic fit' , 'Location' , 'Northwest' ) The ‘c’ values ended up being exactly the same as the previous method. The plot is the exact same as in the previous method....
View Full Document

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes