/*
    File:       Factor.h

    Function:	Provides routines for factoring a matrix:

				+ SVD decomposes A into three matrices, A = U D Vt, where:

					U is m x n, and orthogonal

					D is n x n, and is diagonal; its elements are the
					eigenvalues of AtA.
	
					V is n x n, and orthogonal.

				+ QR factors A into A = Q R, where R is upper-triangular,
				and Q is orthogonal.
					
    Author:     Andrew Willmott

    Copyright:  (c) 1999, Andrew Willmott
*/

#ifndef __Factor__
#define __Factor__

#include "VLd.h"


// --- Factorization routines--------------------------------------------------

Void SVDFactorization(Matd &A, Matd &U, Matd &V, Vecd &diagonal);
// Factor A into U D V
// Destroys A.

Double QRFactorization(Matd &A, Matd &Q, Matd &R);
// Factor A into an orthogonal matrix Q and an upper-triangular matrix R.
// Destroys A.

// --- Utility routines--------------------------------------------------------

Double LeftHouseholder(Matd &A, Matd &U, const Int i);
Double RightHouseholder(Matd &A, Matd &V, const Int i);
Void Bidiagonalize(Matd &A, Matd &U, Matd &V, Vecd &diagonal, Vecd &superDiag);
Void Diagonalize(Vecd &diagonal, Vecd &superDiag, Matd &U, Matd &V);

#endif

