Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.1.2.2591/ALGLIB-2.1.2.2591/sbisinv.cs @ 2645

Last change on this file since 2645 was 2645, checked in by mkommend, 14 years ago

extracted external libraries and adapted dependent plugins (ticket #837)

File size: 8.6 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 sbisinv
26    {
27        /*************************************************************************
28        Subroutine for finding the eigenvalues (and eigenvectors) of  a  symmetric
29        matrix  in  a  given half open interval (A, B] by using  a  bisection  and
30        inverse iteration
31
32        Input parameters:
33            A       -   symmetric matrix which is given by its upper or lower
34                        triangular part. Array [0..N-1, 0..N-1].
35            N       -   size of matrix A.
36            ZNeeded -   flag controlling whether the eigenvectors are needed or not.
37                        If ZNeeded is equal to:
38                         * 0, the eigenvectors are not returned;
39                         * 1, the eigenvectors are returned.
40            IsUpperA -  storage format of matrix A.
41            B1, B2 -    half open interval (B1, B2] to search eigenvalues in.
42
43        Output parameters:
44            M       -   number of eigenvalues found in a given half-interval (M>=0).
45            W       -   array of the eigenvalues found.
46                        Array whose index ranges within [0..M-1].
47            Z       -   if ZNeeded is equal to:
48                         * 0, Z hasn’t changed;
49                         * 1, Z contains eigenvectors.
50                        Array whose indexes range within [0..N-1, 0..M-1].
51                        The eigenvectors are stored in the matrix columns.
52
53        Result:
54            True, if successful. M contains the number of eigenvalues in the given
55            half-interval (could be equal to 0), W contains the eigenvalues,
56            Z contains the eigenvectors (if needed).
57
58            False, if the bisection method subroutine wasn't able to find the
59            eigenvalues in the given interval or if the inverse iteration subroutine
60            wasn't able to find all the corresponding eigenvectors.
61            In that case, the eigenvalues and eigenvectors are not returned,
62            M is equal to 0.
63
64          -- ALGLIB --
65             Copyright 07.01.2006 by Bochkanov Sergey
66        *************************************************************************/
67        public static bool smatrixevdr(double[,] a,
68            int n,
69            int zneeded,
70            bool isupper,
71            double b1,
72            double b2,
73            ref int m,
74            ref double[] w,
75            ref double[,] z)
76        {
77            bool result = new bool();
78            double[] tau = new double[0];
79            double[] e = new double[0];
80
81            a = (double[,])a.Clone();
82
83            System.Diagnostics.Debug.Assert(zneeded==0 | zneeded==1, "SMatrixTDEVDR: incorrect ZNeeded");
84            tridiagonal.smatrixtd(ref a, n, isupper, ref tau, ref w, ref e);
85            if( zneeded==1 )
86            {
87                tridiagonal.smatrixtdunpackq(ref a, n, isupper, ref tau, ref z);
88            }
89            result = tdbisinv.smatrixtdevdr(ref w, ref e, n, zneeded, b1, b2, ref m, ref z);
90            return result;
91        }
92
93
94        /*************************************************************************
95        Subroutine for finding the eigenvalues and  eigenvectors  of  a  symmetric
96        matrix with given indexes by using bisection and inverse iteration methods.
97
98        Input parameters:
99            A       -   symmetric matrix which is given by its upper or lower
100                        triangular part. Array whose indexes range within [0..N-1, 0..N-1].
101            N       -   size of matrix A.
102            ZNeeded -   flag controlling whether the eigenvectors are needed or not.
103                        If ZNeeded is equal to:
104                         * 0, the eigenvectors are not returned;
105                         * 1, the eigenvectors are returned.
106            IsUpperA -  storage format of matrix A.
107            I1, I2 -    index interval for searching (from I1 to I2).
108                        0 <= I1 <= I2 <= N-1.
109
110        Output parameters:
111            W       -   array of the eigenvalues found.
112                        Array whose index ranges within [0..I2-I1].
113            Z       -   if ZNeeded is equal to:
114                         * 0, Z hasn’t changed;
115                         * 1, Z contains eigenvectors.
116                        Array whose indexes range within [0..N-1, 0..I2-I1].
117                        In that case, the eigenvectors are stored in the matrix columns.
118
119        Result:
120            True, if successful. W contains the eigenvalues, Z contains the
121            eigenvectors (if needed).
122
123            False, if the bisection method subroutine wasn't able to find the
124            eigenvalues in the given interval or if the inverse iteration subroutine
125            wasn't able to find all the corresponding eigenvectors.
126            In that case, the eigenvalues and eigenvectors are not returned.
127
128          -- ALGLIB --
129             Copyright 07.01.2006 by Bochkanov Sergey
130        *************************************************************************/
131        public static bool smatrixevdi(double[,] a,
132            int n,
133            int zneeded,
134            bool isupper,
135            int i1,
136            int i2,
137            ref double[] w,
138            ref double[,] z)
139        {
140            bool result = new bool();
141            double[] tau = new double[0];
142            double[] e = new double[0];
143
144            a = (double[,])a.Clone();
145
146            System.Diagnostics.Debug.Assert(zneeded==0 | zneeded==1, "SMatrixEVDI: incorrect ZNeeded");
147            tridiagonal.smatrixtd(ref a, n, isupper, ref tau, ref w, ref e);
148            if( zneeded==1 )
149            {
150                tridiagonal.smatrixtdunpackq(ref a, n, isupper, ref tau, ref z);
151            }
152            result = tdbisinv.smatrixtdevdi(ref w, ref e, n, zneeded, i1, i2, ref z);
153            return result;
154        }
155
156
157        public static bool symmetriceigenvaluesandvectorsininterval(double[,] a,
158            int n,
159            int zneeded,
160            bool isupper,
161            double b1,
162            double b2,
163            ref int m,
164            ref double[] w,
165            ref double[,] z)
166        {
167            bool result = new bool();
168            double[] tau = new double[0];
169            double[] e = new double[0];
170
171            a = (double[,])a.Clone();
172
173            System.Diagnostics.Debug.Assert(zneeded==0 | zneeded==1, "SymmetricEigenValuesAndVectorsInInterval: incorrect ZNeeded");
174            tridiagonal.totridiagonal(ref a, n, isupper, ref tau, ref w, ref e);
175            if( zneeded==1 )
176            {
177                tridiagonal.unpackqfromtridiagonal(ref a, n, isupper, ref tau, ref z);
178            }
179            result = tdbisinv.tridiagonaleigenvaluesandvectorsininterval(ref w, ref e, n, zneeded, b1, b2, ref m, ref z);
180            return result;
181        }
182
183
184        public static bool symmetriceigenvaluesandvectorsbyindexes(double[,] a,
185            int n,
186            int zneeded,
187            bool isupper,
188            int i1,
189            int i2,
190            ref double[] w,
191            ref double[,] z)
192        {
193            bool result = new bool();
194            double[] tau = new double[0];
195            double[] e = new double[0];
196
197            a = (double[,])a.Clone();
198
199            System.Diagnostics.Debug.Assert(zneeded==0 | zneeded==1, "SymmetricEigenValuesAndVectorsInInterval: incorrect ZNeeded");
200            tridiagonal.totridiagonal(ref a, n, isupper, ref tau, ref w, ref e);
201            if( zneeded==1 )
202            {
203                tridiagonal.unpackqfromtridiagonal(ref a, n, isupper, ref tau, ref z);
204            }
205            result = tdbisinv.tridiagonaleigenvaluesandvectorsbyindexes(ref w, ref e, n, zneeded, i1, i2, ref z);
206            return result;
207        }
208    }
209}
Note: See TracBrowser for help on using the repository browser.