Cpsc 440 Problem Set 4 Question 1

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/19/2008 for the course CPSC 440 taught by Professor Vladimirrokhlin during the Spring '08 term at Yale.

Page1 / 5

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

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

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