QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
symmetricschurdecomposition.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file symmetricschurdecomposition.hpp
22 \brief Eigenvalues/eigenvectors of a real symmetric matrix
23*/
24
25#ifndef quantlib_math_jacobi_decomposition_h
26#define quantlib_math_jacobi_decomposition_h
27
28#include <ql/math/matrix.hpp>
29
30namespace QuantLib {
31
32 //! symmetric threshold Jacobi algorithm.
33 /*! Given a real symmetric matrix S, the Schur decomposition
34 finds the eigenvalues and eigenvectors of S. If D is the
35 diagonal matrix formed by the eigenvalues and U the
36 unitarian matrix of the eigenvectors we can write the
37 Schur decomposition as
38 \f[ S = U \cdot D \cdot U^T \, ,\f]
39 where \f$ \cdot \f$ is the standard matrix product
40 and \f$ ^T \f$ is the transpose operator.
41 This class implements the Schur decomposition using the
42 symmetric threshold Jacobi algorithm. For details on the
43 different Jacobi transfomations see "Matrix computation,"
44 second edition, by Golub and Van Loan,
45 The Johns Hopkins University Press
46
47 \test the correctness of the returned values is tested by
48 checking their properties.
49 */
51 public:
52 /*! \pre s must be symmetric */
54 const Array& eigenvalues() const { return diagonal_; }
55 const Matrix& eigenvectors() const { return eigenVectors_; }
56 private:
59 void jacobiRotate_(Matrix & m, Real rot, Real dil,
60 Size j1, Size k1, Size j2, Size k2) const;
61 };
62
63
64 // inline definitions
65
66 //! This routines implements the Jacobi, a.k.a. Givens, rotation
68 Matrix &m, Real rot, Real dil, Size j1,
69 Size k1, Size j2, Size k2) const {
70 Real x1, x2;
71 x1 = m[j1][k1];
72 x2 = m[j2][k2];
73 m[j1][k1] = x1 - dil*(x2 + x1*rot);
74 m[j2][k2] = x2 + dil*(x1 - x2*rot);
75 }
76
77}
78
79
80#endif
81
82
1-D array used in linear algebra.
Definition: array.hpp:52
Matrix used in linear algebra.
Definition: matrix.hpp:41
symmetric threshold Jacobi algorithm.
void jacobiRotate_(Matrix &m, Real rot, Real dil, Size j1, Size k1, Size j2, Size k2) const
This routines implements the Jacobi, a.k.a. Givens, rotation.
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
matrix used in linear algebra.
Definition: any.hpp:35