E7_Lab11_Solutions_Fall_2010

E7_Lab11_Solutions_Fall_2010 - Contents Problem 1 Problem 2...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Contents Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 problem 6 problem 7 Problem 1 x=1:10; y=[-2 3 -4 6 -7 10 -17 25 -26 63]; xi=1:0.1:10; yi_l=interp1(x,y,xi, 'linear' ); yi_c=interp1(x,y,xi, 'cubic' ); yi_s=interp1(x,y,xi, 'spline' ); plot(x,y, 'o' ,xi,yi_l, '--' ,xi,yi_c, ':' ,xi,yi_s) legend( 'original' , 'linear' , 'cubic' , 'spline' ) Problem 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
type my_ls function [coefficients] = my_ls(x_values,y_values,d) sx=size(x_values); sy=size(y_values); if sx(1)==1 x_v=x_values'; %convert row vector into column vector else x_v=x_values; end if sy(1)==1 y_v=y_values'; %convert row vector into column vector else y_v=y_values; end n = length(x_v); x=[]; for i=1:d x= [x x_v.^i]; end X= [ones(n,1) x]; a=X\y_v; coefficients=a; %gives coefficients in order from. .. %ao + a1*x1 + a2*x2. ... Problem 3 clf data=load( 'curve.txt' ); x=data(:,1)'; y=data(:,2)'; %part a d1=1; [c1]=my_ls(x,y,d1); y_lin=c1(1) + c1(2).*x; plot(x,y_lin, 'r-' , 'LineWidth' ,3) hold on d2=2; [c2]=my_ls(x,y,d2); y_2=c2(1) + c2(2).*x + c2(3).*x.^2; plot(x,y_2, 'k' , 'LineWidth' ,4.5)
Background image of page 2
hold on plot(x,y, '.' ) legend( 'linear' , 'quadratic' , 'given' ) %part b %This regression is a second degree polynomial %part c c2 %part d The results should be identical except that polyfit gives the
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

E7_Lab11_Solutions_Fall_2010 - Contents Problem 1 Problem 2...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online