E7_Lab11_Solutions_Fall_2010

E7_Lab11_Solutions_Fall_2010 - Contents Problem 1 Problem 2...

Info icon This 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
Image of page 1

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

View Full Document Right 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)
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
Image of page 3

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

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

{[ snackBarMessage ]}

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