{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Cpsc 440 Problem Set 4 Question 1

# Cpsc 440 Problem Set 4 Question 1 - hw4p1.h#ifndef...

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

hw4p1.h 5/12/2008 # ifndef HW4P1_H # define HW4P1_H # include "matrix.h" matrix matrixSquareRoot ( matrix m ) ; matrix matrixNewtonSquareRoot ( matrix m ) ; matrix matrixPower ( matrix m , double power ) ; # endif 1

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

View Full Document
5/12/2008 # include < math . h > # include < stdio . h > # include < stdlib . h > # include "hw4p1.h" # define SQRT_ERROR_TOLERANCE 1e-12 matrix matrixSquareRoot ( matrix m ) { matrix Y = matrixCopy ( m ) ; matrix Z = identityMatrix ( getNumRows ( m )) ; matrix Y2 = matrixProduct ( Y , Y ) ; double epsilon = matrixTotalAbsoluteDifference ( m , Y2 ) ; while ( epsilon > SQRT_ERROR_TOLERANCE ) { matrix YINV = matrixInverse ( Y ) ; matrix ZINV = matrixInverse ( Z ) ; matrix Y0 = matrixCopy ( Y ) ; matrix Z0 = matrixCopy ( Z ) ; freeMatrix ( Y ) ; freeMatrix ( Z ) ; Y = matrixLinearCombination ( 0.5 , Y0 , 0.5 , ZINV ) ; Z = matrixLinearCombination ( 0.5 , Z0 , 0.5 , YINV ) ; freeMatrix ( YINV ) ; freeMatrix ( ZINV ) ; freeMatrix ( Y0 ) ; freeMatrix ( Z0 ) ; freeMatrix ( Y2 ) ; Y2 = matrixProduct ( Y , Y ) ; double epsilon_new = matrixTotalAbsoluteDifference ( m , Y2 ) ; if ( epsilon_new > epsilon ) { break
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

Cpsc 440 Problem Set 4 Question 1 - hw4p1.h#ifndef...

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

View Full Document
Ask a homework question - tutors are online