hw4s.pdf

# hw4s.pdf - COMPUTER SCIENCE 50100 Computing for Science and...

• Homework Help
• 6

This preview shows pages 1–2. Sign up to view the full content.

COMPUTER SCIENCE 50100 Computing for Science and Engineering FALL 2015 ASSIGNMENT # 4 Solutions (35 points) November 6 This assignment covers Sections 4.2.2–4.5 of the class notes. Your C code should conform to the C11 standard. The use of continue is not permitted. Every loop is permitted to have only one exit. In particular, a break statement is permitted as an exit only for a loop with header “ while (true) ”. Do not use nested if s when short circuit evaluation works. Memory leaks are not permitted. 1. (15 points) A symmetric matrix A is positive definite if and only if it can be factored as A = GG T where the Cholesky factor G is lower triangular with positive diagonal elements. The Cholesky factor G = chol ( A ) can be define recursively by chol([ α ]) = [ α 1 / 2 ] and chol α a T a ˆ A = " α 1 / 2 0 α - 1 / 2 a chol ˆ A - α - 1 aa T # where α is a scalar and a is a column vector. You are to create a file chol.c that defines two different implementations of this algorithm. Both implementations assume that only the lower triangular part of A is given, and both overwrite it with G . Both implementations should halt the calculation if α is ever nonpositive and return the value - 1; otherwise it should return 0. (a) (8 points) The first implementation has prototype int chol(int n, int ndim, double (*a)[ndim]) and is to be a faithful recursive rendition of the alogrithm given above. The array a is assumed to have n or more rows and ndim columns and assumed to contain the lower triangular part of an n by n matrix. (b) (7 points) The second implementation has prototype int chol2(int n, double **a); and is to be a nonrecursive (but otherwise faithful) rendition of the algorithm given above. The array a is assumed to be a one-dimensional array of pointers , with a[i]

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

This is the end of the preview. Sign up to access the rest of the document.
• Spring '14
• AlexPothen
• Computer Science, Return statement, Void type, Array data structure, int index

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern