Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/ALGLIB/sevd.cs @ 2563

Last change on this file since 2563 was 2563, checked in by gkronber, 14 years ago

Updated ALGLIB to latest version. #751 (Plugin for for data-modeling with ANN (integrated into CEDMA))

File size: 4.1 KB
Line 
1/*************************************************************************
2Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
3
4>>> SOURCE LICENSE >>>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation (www.fsf.org); either version 2 of the
8License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15A copy of the GNU General Public License is available at
16http://www.fsf.org/licensing/licenses
17
18>>> END OF LICENSE >>>
19*************************************************************************/
20
21using System;
22
23namespace alglib
24{
25    public class sevd
26    {
27        /*************************************************************************
28        Finding the eigenvalues and eigenvectors of a symmetric matrix
29
30        The algorithm finds eigen pairs of a symmetric matrix by reducing it to
31        tridiagonal form and using the QL/QR algorithm.
32
33        Input parameters:
34            A       -   symmetric matrix which is given by its upper or lower
35                        triangular part.
36                        Array whose indexes range within [0..N-1, 0..N-1].
37            N       -   size of matrix A.
38            IsUpper -   storage format.
39            ZNeeded -   flag controlling whether the eigenvectors are needed or not.
40                        If ZNeeded is equal to:
41                         * 0, the eigenvectors are not returned;
42                         * 1, the eigenvectors are returned.
43
44        Output parameters:
45            D       -   eigenvalues in ascending order.
46                        Array whose index ranges within [0..N-1].
47            Z       -   if ZNeeded is equal to:
48                         * 0, Z hasn’t changed;
49                         * 1, Z contains the eigenvectors.
50                        Array whose indexes range within [0..N-1, 0..N-1].
51                        The eigenvectors are stored in the matrix columns.
52
53        Result:
54            True, if the algorithm has converged.
55            False, if the algorithm hasn't converged (rare case).
56
57          -- ALGLIB --
58             Copyright 2005-2008 by Bochkanov Sergey
59        *************************************************************************/
60        public static bool smatrixevd(double[,] a,
61            int n,
62            int zneeded,
63            bool isupper,
64            ref double[] d,
65            ref double[,] z)
66        {
67            bool result = new bool();
68            double[] tau = new double[0];
69            double[] e = new double[0];
70
71            a = (double[,])a.Clone();
72
73            System.Diagnostics.Debug.Assert(zneeded==0 | zneeded==1, "SMatrixEVD: incorrect ZNeeded");
74            tridiagonal.smatrixtd(ref a, n, isupper, ref tau, ref d, ref e);
75            if( zneeded==1 )
76            {
77                tridiagonal.smatrixtdunpackq(ref a, n, isupper, ref tau, ref z);
78            }
79            result = tdevd.smatrixtdevd(ref d, e, n, zneeded, ref z);
80            return result;
81        }
82
83
84        public static bool symmetricevd(double[,] a,
85            int n,
86            int zneeded,
87            bool isupper,
88            ref double[] d,
89            ref double[,] z)
90        {
91            bool result = new bool();
92            double[] tau = new double[0];
93            double[] e = new double[0];
94
95            a = (double[,])a.Clone();
96
97            System.Diagnostics.Debug.Assert(zneeded==0 | zneeded==1, "SymmetricEVD: incorrect ZNeeded");
98            tridiagonal.totridiagonal(ref a, n, isupper, ref tau, ref d, ref e);
99            if( zneeded==1 )
100            {
101                tridiagonal.unpackqfromtridiagonal(ref a, n, isupper, ref tau, ref z);
102            }
103            result = tdevd.tridiagonalevd(ref d, e, n, zneeded, ref z);
104            return result;
105        }
106    }
107}
Note: See TracBrowser for help on using the repository browser.