**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

- Fall '13
- Linear Algebra, Algebra, matlab