STA5106_FRADE_HW2

STA5106_FRADE_HW2 - STA5106 Dr Srivastava Homework 2 Jaime...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
STA5106: Dr. Srivastava Homework 2 Jaime Frade 1. variance.m OUTPUT >> x=randn(1,100); >> variance3(x) variance3 = 0.9258 CODE function V=variance3(x) g=x(1); s1=0; s2=0; k=0; E=0.01; n=size(x,2); while (k<n) while (k<n & abs(s1)<E) k=k+1; s1= s1+(x(k)-g); s2=s2+(x(k)-g)*(x(k)-g); end if (k<n) gn=(s1/k)+g; s2 = s2 -k*(gn-g)+(gn-g)-2*(gn-g)*s1; s1=0; gn=0; end end m = s1/n+g; variance3 = s2/n - (s1/n)^2 end
Image of page 1

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

View Full Document Right Arrow Icon
STA5106: Dr. Srivastava Homework 2 Jaime Frade 2. backsub.m OUTPUT >> x = [12 10 13 10;0 7 1 4; 0 0 3 2; 0 0 0 4] x = 12 10 13 10 0 7 1 4 0 0 3 2 0 0 0 4 >> y = [1;1;1;1] y = 1 1 1 1 >> backsub(x,y) ans = -0.285714285714286 -0.023809523809524 0.166666666666667 0.250000000000000 >> b = x\y b = -0.285714285714286 -0.023809523809524 0.166666666666667 0.250000000000000 Comments: Test the function by using built-in matlab operator
Image of page 2
STA5106: Dr. Srivastava Homework 2 Jaime Frade CODE %works same as built-in funtion operator, backslash\ %solves a system, Ax=b, where A is an upper %right triangluar matrix. %Not possible: solve an upper Triag matrix for nonsigular A function b=backsub(x,y) n=size(x,2); b(n,1) = y(n,1)/x(n,n); format long for j=(n-1):-1:1 b(j,1)= (y(j,1)-x(j,j+1:n)*b(j+1:n,1))/x(j,j); end
Image of page 3

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

View Full Document Right Arrow Icon
STA5106: Dr. Srivastava Homework 2 Jaime Frade 3.
Image of page 4
Image of page 5
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