alglib 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Manifest.txt +253 -0
- data/README.txt +33 -0
- data/Rakefile +27 -0
- data/ext/Rakefile +24 -0
- data/ext/alglib.i +24 -0
- data/ext/alglib/Makefile +157 -0
- data/ext/alglib/airyf.cpp +372 -0
- data/ext/alglib/airyf.h +81 -0
- data/ext/alglib/alglib.cpp +8558 -0
- data/ext/alglib/alglib_util.cpp +19 -0
- data/ext/alglib/alglib_util.h +14 -0
- data/ext/alglib/ap.cpp +877 -0
- data/ext/alglib/ap.english.html +364 -0
- data/ext/alglib/ap.h +666 -0
- data/ext/alglib/ap.russian.html +442 -0
- data/ext/alglib/apvt.h +754 -0
- data/ext/alglib/bdss.cpp +1500 -0
- data/ext/alglib/bdss.h +251 -0
- data/ext/alglib/bdsvd.cpp +1339 -0
- data/ext/alglib/bdsvd.h +164 -0
- data/ext/alglib/bessel.cpp +1226 -0
- data/ext/alglib/bessel.h +331 -0
- data/ext/alglib/betaf.cpp +105 -0
- data/ext/alglib/betaf.h +74 -0
- data/ext/alglib/bidiagonal.cpp +1328 -0
- data/ext/alglib/bidiagonal.h +350 -0
- data/ext/alglib/binomialdistr.cpp +247 -0
- data/ext/alglib/binomialdistr.h +153 -0
- data/ext/alglib/blas.cpp +576 -0
- data/ext/alglib/blas.h +132 -0
- data/ext/alglib/cblas.cpp +226 -0
- data/ext/alglib/cblas.h +57 -0
- data/ext/alglib/cdet.cpp +138 -0
- data/ext/alglib/cdet.h +92 -0
- data/ext/alglib/chebyshev.cpp +216 -0
- data/ext/alglib/chebyshev.h +76 -0
- data/ext/alglib/chisquaredistr.cpp +157 -0
- data/ext/alglib/chisquaredistr.h +144 -0
- data/ext/alglib/cholesky.cpp +285 -0
- data/ext/alglib/cholesky.h +86 -0
- data/ext/alglib/cinverse.cpp +298 -0
- data/ext/alglib/cinverse.h +111 -0
- data/ext/alglib/clu.cpp +337 -0
- data/ext/alglib/clu.h +120 -0
- data/ext/alglib/correlation.cpp +280 -0
- data/ext/alglib/correlation.h +77 -0
- data/ext/alglib/correlationtests.cpp +726 -0
- data/ext/alglib/correlationtests.h +134 -0
- data/ext/alglib/crcond.cpp +826 -0
- data/ext/alglib/crcond.h +148 -0
- data/ext/alglib/creflections.cpp +310 -0
- data/ext/alglib/creflections.h +165 -0
- data/ext/alglib/csolve.cpp +312 -0
- data/ext/alglib/csolve.h +99 -0
- data/ext/alglib/ctrinverse.cpp +387 -0
- data/ext/alglib/ctrinverse.h +98 -0
- data/ext/alglib/ctrlinsolve.cpp +297 -0
- data/ext/alglib/ctrlinsolve.h +81 -0
- data/ext/alglib/dawson.cpp +234 -0
- data/ext/alglib/dawson.h +74 -0
- data/ext/alglib/descriptivestatistics.cpp +436 -0
- data/ext/alglib/descriptivestatistics.h +112 -0
- data/ext/alglib/det.cpp +140 -0
- data/ext/alglib/det.h +94 -0
- data/ext/alglib/dforest.cpp +1819 -0
- data/ext/alglib/dforest.h +316 -0
- data/ext/alglib/elliptic.cpp +497 -0
- data/ext/alglib/elliptic.h +217 -0
- data/ext/alglib/estnorm.cpp +429 -0
- data/ext/alglib/estnorm.h +107 -0
- data/ext/alglib/expintegrals.cpp +422 -0
- data/ext/alglib/expintegrals.h +108 -0
- data/ext/alglib/faq.english.html +258 -0
- data/ext/alglib/faq.russian.html +272 -0
- data/ext/alglib/fdistr.cpp +202 -0
- data/ext/alglib/fdistr.h +163 -0
- data/ext/alglib/fresnel.cpp +211 -0
- data/ext/alglib/fresnel.h +91 -0
- data/ext/alglib/gammaf.cpp +338 -0
- data/ext/alglib/gammaf.h +104 -0
- data/ext/alglib/gqgengauss.cpp +235 -0
- data/ext/alglib/gqgengauss.h +92 -0
- data/ext/alglib/gqgenhermite.cpp +268 -0
- data/ext/alglib/gqgenhermite.h +63 -0
- data/ext/alglib/gqgenjacobi.cpp +297 -0
- data/ext/alglib/gqgenjacobi.h +72 -0
- data/ext/alglib/gqgenlaguerre.cpp +265 -0
- data/ext/alglib/gqgenlaguerre.h +69 -0
- data/ext/alglib/gqgenlegendre.cpp +300 -0
- data/ext/alglib/gqgenlegendre.h +62 -0
- data/ext/alglib/gqgenlobatto.cpp +305 -0
- data/ext/alglib/gqgenlobatto.h +97 -0
- data/ext/alglib/gqgenradau.cpp +232 -0
- data/ext/alglib/gqgenradau.h +95 -0
- data/ext/alglib/hbisinv.cpp +480 -0
- data/ext/alglib/hbisinv.h +183 -0
- data/ext/alglib/hblas.cpp +228 -0
- data/ext/alglib/hblas.h +64 -0
- data/ext/alglib/hcholesky.cpp +339 -0
- data/ext/alglib/hcholesky.h +91 -0
- data/ext/alglib/hermite.cpp +114 -0
- data/ext/alglib/hermite.h +49 -0
- data/ext/alglib/hessenberg.cpp +370 -0
- data/ext/alglib/hessenberg.h +152 -0
- data/ext/alglib/hevd.cpp +247 -0
- data/ext/alglib/hevd.h +107 -0
- data/ext/alglib/hsschur.cpp +1316 -0
- data/ext/alglib/hsschur.h +108 -0
- data/ext/alglib/htridiagonal.cpp +734 -0
- data/ext/alglib/htridiagonal.h +180 -0
- data/ext/alglib/ialglib.cpp +6 -0
- data/ext/alglib/ialglib.h +9 -0
- data/ext/alglib/ibetaf.cpp +960 -0
- data/ext/alglib/ibetaf.h +125 -0
- data/ext/alglib/igammaf.cpp +430 -0
- data/ext/alglib/igammaf.h +157 -0
- data/ext/alglib/inv.cpp +274 -0
- data/ext/alglib/inv.h +115 -0
- data/ext/alglib/inverseupdate.cpp +480 -0
- data/ext/alglib/inverseupdate.h +185 -0
- data/ext/alglib/jacobianelliptic.cpp +164 -0
- data/ext/alglib/jacobianelliptic.h +94 -0
- data/ext/alglib/jarquebera.cpp +2271 -0
- data/ext/alglib/jarquebera.h +80 -0
- data/ext/alglib/kmeans.cpp +356 -0
- data/ext/alglib/kmeans.h +76 -0
- data/ext/alglib/laguerre.cpp +94 -0
- data/ext/alglib/laguerre.h +48 -0
- data/ext/alglib/lbfgs.cpp +1167 -0
- data/ext/alglib/lbfgs.h +218 -0
- data/ext/alglib/lda.cpp +434 -0
- data/ext/alglib/lda.h +133 -0
- data/ext/alglib/ldlt.cpp +1130 -0
- data/ext/alglib/ldlt.h +124 -0
- data/ext/alglib/leastsquares.cpp +1252 -0
- data/ext/alglib/leastsquares.h +290 -0
- data/ext/alglib/legendre.cpp +107 -0
- data/ext/alglib/legendre.h +49 -0
- data/ext/alglib/linreg.cpp +1185 -0
- data/ext/alglib/linreg.h +380 -0
- data/ext/alglib/logit.cpp +1523 -0
- data/ext/alglib/logit.h +333 -0
- data/ext/alglib/lq.cpp +399 -0
- data/ext/alglib/lq.h +160 -0
- data/ext/alglib/lu.cpp +462 -0
- data/ext/alglib/lu.h +119 -0
- data/ext/alglib/mannwhitneyu.cpp +4490 -0
- data/ext/alglib/mannwhitneyu.h +115 -0
- data/ext/alglib/minlm.cpp +918 -0
- data/ext/alglib/minlm.h +312 -0
- data/ext/alglib/mlpbase.cpp +3375 -0
- data/ext/alglib/mlpbase.h +589 -0
- data/ext/alglib/mlpe.cpp +1369 -0
- data/ext/alglib/mlpe.h +552 -0
- data/ext/alglib/mlptrain.cpp +1056 -0
- data/ext/alglib/mlptrain.h +283 -0
- data/ext/alglib/nearunityunit.cpp +91 -0
- data/ext/alglib/nearunityunit.h +17 -0
- data/ext/alglib/normaldistr.cpp +377 -0
- data/ext/alglib/normaldistr.h +175 -0
- data/ext/alglib/nsevd.cpp +1869 -0
- data/ext/alglib/nsevd.h +140 -0
- data/ext/alglib/pca.cpp +168 -0
- data/ext/alglib/pca.h +87 -0
- data/ext/alglib/poissondistr.cpp +143 -0
- data/ext/alglib/poissondistr.h +130 -0
- data/ext/alglib/polinterpolation.cpp +685 -0
- data/ext/alglib/polinterpolation.h +206 -0
- data/ext/alglib/psif.cpp +173 -0
- data/ext/alglib/psif.h +88 -0
- data/ext/alglib/qr.cpp +414 -0
- data/ext/alglib/qr.h +168 -0
- data/ext/alglib/ratinterpolation.cpp +134 -0
- data/ext/alglib/ratinterpolation.h +72 -0
- data/ext/alglib/rcond.cpp +705 -0
- data/ext/alglib/rcond.h +140 -0
- data/ext/alglib/reflections.cpp +504 -0
- data/ext/alglib/reflections.h +165 -0
- data/ext/alglib/rotations.cpp +473 -0
- data/ext/alglib/rotations.h +128 -0
- data/ext/alglib/rsolve.cpp +221 -0
- data/ext/alglib/rsolve.h +99 -0
- data/ext/alglib/sbisinv.cpp +217 -0
- data/ext/alglib/sbisinv.h +171 -0
- data/ext/alglib/sblas.cpp +185 -0
- data/ext/alglib/sblas.h +64 -0
- data/ext/alglib/schur.cpp +156 -0
- data/ext/alglib/schur.h +102 -0
- data/ext/alglib/sdet.cpp +193 -0
- data/ext/alglib/sdet.h +101 -0
- data/ext/alglib/sevd.cpp +116 -0
- data/ext/alglib/sevd.h +99 -0
- data/ext/alglib/sinverse.cpp +672 -0
- data/ext/alglib/sinverse.h +138 -0
- data/ext/alglib/spddet.cpp +138 -0
- data/ext/alglib/spddet.h +96 -0
- data/ext/alglib/spdgevd.cpp +842 -0
- data/ext/alglib/spdgevd.h +200 -0
- data/ext/alglib/spdinverse.cpp +509 -0
- data/ext/alglib/spdinverse.h +122 -0
- data/ext/alglib/spdrcond.cpp +421 -0
- data/ext/alglib/spdrcond.h +118 -0
- data/ext/alglib/spdsolve.cpp +275 -0
- data/ext/alglib/spdsolve.h +105 -0
- data/ext/alglib/spline2d.cpp +1192 -0
- data/ext/alglib/spline2d.h +301 -0
- data/ext/alglib/spline3.cpp +1264 -0
- data/ext/alglib/spline3.h +290 -0
- data/ext/alglib/srcond.cpp +595 -0
- data/ext/alglib/srcond.h +127 -0
- data/ext/alglib/ssolve.cpp +895 -0
- data/ext/alglib/ssolve.h +139 -0
- data/ext/alglib/stdafx.h +0 -0
- data/ext/alglib/stest.cpp +131 -0
- data/ext/alglib/stest.h +94 -0
- data/ext/alglib/studenttdistr.cpp +222 -0
- data/ext/alglib/studenttdistr.h +115 -0
- data/ext/alglib/studentttests.cpp +377 -0
- data/ext/alglib/studentttests.h +178 -0
- data/ext/alglib/svd.cpp +620 -0
- data/ext/alglib/svd.h +126 -0
- data/ext/alglib/tdbisinv.cpp +2608 -0
- data/ext/alglib/tdbisinv.h +228 -0
- data/ext/alglib/tdevd.cpp +1229 -0
- data/ext/alglib/tdevd.h +115 -0
- data/ext/alglib/tridiagonal.cpp +594 -0
- data/ext/alglib/tridiagonal.h +171 -0
- data/ext/alglib/trigintegrals.cpp +490 -0
- data/ext/alglib/trigintegrals.h +131 -0
- data/ext/alglib/trinverse.cpp +345 -0
- data/ext/alglib/trinverse.h +98 -0
- data/ext/alglib/trlinsolve.cpp +926 -0
- data/ext/alglib/trlinsolve.h +73 -0
- data/ext/alglib/tsort.cpp +405 -0
- data/ext/alglib/tsort.h +54 -0
- data/ext/alglib/variancetests.cpp +245 -0
- data/ext/alglib/variancetests.h +134 -0
- data/ext/alglib/wsr.cpp +6285 -0
- data/ext/alglib/wsr.h +96 -0
- data/ext/ap.i +97 -0
- data/ext/correlation.i +24 -0
- data/ext/extconf.rb +6 -0
- data/ext/logit.i +89 -0
- data/lib/alglib.rb +71 -0
- data/lib/alglib/correlation.rb +26 -0
- data/lib/alglib/linearregression.rb +63 -0
- data/lib/alglib/logit.rb +42 -0
- data/test/test_alglib.rb +52 -0
- data/test/test_correlation.rb +44 -0
- data/test/test_correlationtest.rb +45 -0
- data/test/test_linreg.rb +35 -0
- data/test/test_logit.rb +43 -0
- data/test/test_pca.rb +27 -0
- metadata +326 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
- Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer listed
|
13
|
+
in this license in the documentation and/or other materials
|
14
|
+
provided with the distribution.
|
15
|
+
|
16
|
+
- Neither the name of the copyright holders nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*************************************************************************/
|
32
|
+
|
33
|
+
#ifndef _gqgenlobatto_h
|
34
|
+
#define _gqgenlobatto_h
|
35
|
+
|
36
|
+
#include "ap.h"
|
37
|
+
#include "ialglib.h"
|
38
|
+
|
39
|
+
#include "blas.h"
|
40
|
+
#include "rotations.h"
|
41
|
+
#include "tdevd.h"
|
42
|
+
|
43
|
+
|
44
|
+
/*************************************************************************
|
45
|
+
Computation of nodes and weights for a Gauss-Lobatto quadrature formula
|
46
|
+
|
47
|
+
The algorithm generates the N-point Gauss-Lobatto quadrature formula with
|
48
|
+
weight function given by coefficients alpha and beta of a recurrence which
|
49
|
+
generates a system of orthogonal polynomials.
|
50
|
+
|
51
|
+
P-1(x) = 0
|
52
|
+
P0(x) = 1
|
53
|
+
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
|
54
|
+
|
55
|
+
and zero moment Mu0
|
56
|
+
|
57
|
+
Mu0 = integral(W(x)dx,a,b)
|
58
|
+
|
59
|
+
|
60
|
+
Input parameters:
|
61
|
+
Alpha � array of coefficients.
|
62
|
+
Array whose index ranges within [0..N-2].
|
63
|
+
Beta � array of coefficients.
|
64
|
+
Array whose index ranges within [0..N-2].
|
65
|
+
Zero-indexed element is not used.
|
66
|
+
Beta[I]>0
|
67
|
+
Mu0 � zero moment of the weighting function.
|
68
|
+
A � left boundary of the integration interval.
|
69
|
+
B � right boundary of the integration interval.
|
70
|
+
N � number of nodes of the quadrature formula, N>=3
|
71
|
+
(including the left and right boundary nodes).
|
72
|
+
|
73
|
+
Output parameters:
|
74
|
+
X � array of nodes of the quadrature formula (in ascending order).
|
75
|
+
Array whose index ranges within [0..N-1].
|
76
|
+
W � array of weights of the quadrature formula.
|
77
|
+
Array whose index ranges within [0..N-1].
|
78
|
+
|
79
|
+
Result:
|
80
|
+
True, if the algorithm finished its work successfully.
|
81
|
+
False, if the algorithm of finding the eigenvalues has not converged,
|
82
|
+
or one or more of the Beta coefficients is less or equal to 0.
|
83
|
+
|
84
|
+
-- ALGLIB --
|
85
|
+
Copyright 2005 by Bochkanov Sergey
|
86
|
+
*************************************************************************/
|
87
|
+
bool generategausslobattoquadrature(ap::real_1d_array alpha,
|
88
|
+
ap::real_1d_array beta,
|
89
|
+
double mu0,
|
90
|
+
double a,
|
91
|
+
double b,
|
92
|
+
int n,
|
93
|
+
ap::real_1d_array& x,
|
94
|
+
ap::real_1d_array& w);
|
95
|
+
|
96
|
+
|
97
|
+
#endif
|
@@ -0,0 +1,232 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
- Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer listed
|
13
|
+
in this license in the documentation and/or other materials
|
14
|
+
provided with the distribution.
|
15
|
+
|
16
|
+
- Neither the name of the copyright holders nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*************************************************************************/
|
32
|
+
|
33
|
+
#include <stdafx.h>
|
34
|
+
#include <stdio.h>
|
35
|
+
#include "gqgenradau.h"
|
36
|
+
|
37
|
+
static void testgenerategaussradauquadrature();
|
38
|
+
|
39
|
+
/*************************************************************************
|
40
|
+
Computation of nodes and weights for a Gauss-Radua quadrature formula
|
41
|
+
|
42
|
+
The algorithm generates the N-point Gauss-Radau quadrature formula with
|
43
|
+
weight function given by the coefficients alpha and beta of a recurrence
|
44
|
+
which generates a system of orthogonal polynomials.
|
45
|
+
|
46
|
+
P-1(x) = 0
|
47
|
+
P0(x) = 1
|
48
|
+
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
|
49
|
+
|
50
|
+
and zero moment Mu0
|
51
|
+
|
52
|
+
Mu0 = integral(W(x)dx,a,b)
|
53
|
+
|
54
|
+
|
55
|
+
Input parameters:
|
56
|
+
Alpha � array of coefficients.
|
57
|
+
Array whose index ranges within [0..N-2].
|
58
|
+
Beta � array of coefficients.
|
59
|
+
Array whose index ranges within [0..N-1].
|
60
|
+
Zero-indexed element is not used.
|
61
|
+
Beta[I]>0
|
62
|
+
Mu0 � zero moment of the weighting function.
|
63
|
+
A � left boundary of the integration interval.
|
64
|
+
N � number of nodes of the quadrature formula, N>=2
|
65
|
+
(including the left boundary node).
|
66
|
+
|
67
|
+
Output parameters:
|
68
|
+
X � array of nodes of the quadrature formula (in ascending order).
|
69
|
+
Array whose index ranges within [0..N-1].
|
70
|
+
W � array of weights of the quadrature formula.
|
71
|
+
Array whose index ranges within [0..N-1].
|
72
|
+
|
73
|
+
Result:
|
74
|
+
True, if the algorithm finished its work successfully.
|
75
|
+
False, if the algorithm of finding eigenvalues has not converged, or
|
76
|
+
one or more of the Beta coefficients is less or equal to 0.
|
77
|
+
|
78
|
+
-- ALGLIB --
|
79
|
+
Copyright 2005 by Bochkanov Sergey
|
80
|
+
*************************************************************************/
|
81
|
+
bool generategaussradauquadrature(ap::real_1d_array alpha,
|
82
|
+
ap::real_1d_array beta,
|
83
|
+
double mu0,
|
84
|
+
double a,
|
85
|
+
int n,
|
86
|
+
ap::real_1d_array& x,
|
87
|
+
ap::real_1d_array& w)
|
88
|
+
{
|
89
|
+
bool result;
|
90
|
+
int i;
|
91
|
+
ap::real_1d_array d;
|
92
|
+
ap::real_1d_array e;
|
93
|
+
ap::real_2d_array z;
|
94
|
+
double polim1;
|
95
|
+
double poli;
|
96
|
+
double t;
|
97
|
+
|
98
|
+
if( n<2 )
|
99
|
+
{
|
100
|
+
result = false;
|
101
|
+
return result;
|
102
|
+
}
|
103
|
+
|
104
|
+
//
|
105
|
+
// Initialize, D[1:N], E[1:N]
|
106
|
+
//
|
107
|
+
n = n-1;
|
108
|
+
d.setbounds(1, n+1);
|
109
|
+
e.setbounds(1, n);
|
110
|
+
for(i = 1; i <= n; i++)
|
111
|
+
{
|
112
|
+
d(i) = alpha(i-1);
|
113
|
+
if( beta(i)<=0 )
|
114
|
+
{
|
115
|
+
result = false;
|
116
|
+
return result;
|
117
|
+
}
|
118
|
+
e(i) = sqrt(beta(i));
|
119
|
+
}
|
120
|
+
|
121
|
+
//
|
122
|
+
// Caclulate Pn(a), Pn-1(a), and D[N+1]
|
123
|
+
//
|
124
|
+
beta(0) = 0;
|
125
|
+
polim1 = 0;
|
126
|
+
poli = 1;
|
127
|
+
for(i = 1; i <= n; i++)
|
128
|
+
{
|
129
|
+
t = (a-alpha(i-1))*poli-beta(i-1)*polim1;
|
130
|
+
polim1 = poli;
|
131
|
+
poli = t;
|
132
|
+
}
|
133
|
+
d(n+1) = a-beta(n)*polim1/poli;
|
134
|
+
|
135
|
+
//
|
136
|
+
// EVD
|
137
|
+
//
|
138
|
+
result = tridiagonalevd(d, e, n+1, 3, z);
|
139
|
+
if( !result )
|
140
|
+
{
|
141
|
+
return result;
|
142
|
+
}
|
143
|
+
|
144
|
+
//
|
145
|
+
// Generate
|
146
|
+
//
|
147
|
+
x.setbounds(0, n);
|
148
|
+
w.setbounds(0, n);
|
149
|
+
for(i = 1; i <= n+1; i++)
|
150
|
+
{
|
151
|
+
x(i-1) = d(i);
|
152
|
+
w(i-1) = mu0*ap::sqr(z(1,i));
|
153
|
+
}
|
154
|
+
return result;
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
static void testgenerategaussradauquadrature()
|
159
|
+
{
|
160
|
+
ap::real_1d_array alpha;
|
161
|
+
ap::real_1d_array beta;
|
162
|
+
ap::real_1d_array x;
|
163
|
+
ap::real_1d_array w;
|
164
|
+
double err;
|
165
|
+
int i;
|
166
|
+
|
167
|
+
printf("TESTING GAUSS-RADAU QUADRATURES GENERATION\n");
|
168
|
+
|
169
|
+
//
|
170
|
+
// first test
|
171
|
+
//
|
172
|
+
alpha.setbounds(0, 0);
|
173
|
+
beta.setbounds(0, 1);
|
174
|
+
alpha(0) = 0;
|
175
|
+
beta(0) = 0;
|
176
|
+
beta(1) = double(1*1)/double(4*1*1-1);
|
177
|
+
generategaussradauquadrature(alpha, beta, 2.0, double(-1), 2, x, w);
|
178
|
+
err = 0;
|
179
|
+
err = ap::maxreal(err, fabs(x(0)+1));
|
180
|
+
err = ap::maxreal(err, fabs(x(1)-double(1)/double(3)));
|
181
|
+
err = ap::maxreal(err, fabs(w(0)-0.5));
|
182
|
+
err = ap::maxreal(err, fabs(w(1)-1.5));
|
183
|
+
printf("First test (Gauss-Radau 2): error is %6.3le\n",
|
184
|
+
double(err));
|
185
|
+
|
186
|
+
//
|
187
|
+
// second test
|
188
|
+
//
|
189
|
+
alpha.setbounds(0, 1);
|
190
|
+
beta.setbounds(0, 2);
|
191
|
+
alpha(0) = 0;
|
192
|
+
alpha(1) = 0;
|
193
|
+
for(i = 0; i <= 2; i++)
|
194
|
+
{
|
195
|
+
beta(i) = ap::sqr(double(i))/(4*ap::sqr(double(i))-1);
|
196
|
+
}
|
197
|
+
generategaussradauquadrature(alpha, beta, 2.0, double(-1), 3, x, w);
|
198
|
+
err = 0;
|
199
|
+
err = ap::maxreal(err, fabs(x(0)+1));
|
200
|
+
err = ap::maxreal(err, fabs(x(1)-(1-sqrt(double(6)))/5));
|
201
|
+
err = ap::maxreal(err, fabs(x(2)-(1+sqrt(double(6)))/5));
|
202
|
+
err = ap::maxreal(err, fabs(w(0)-double(2)/double(9)));
|
203
|
+
err = ap::maxreal(err, fabs(w(1)-(16+sqrt(double(6)))/18));
|
204
|
+
err = ap::maxreal(err, fabs(w(2)-(16-sqrt(double(6)))/18));
|
205
|
+
printf("Second test (Gauss-Radau 3): error is %6.3le\n",
|
206
|
+
double(err));
|
207
|
+
|
208
|
+
//
|
209
|
+
// third test
|
210
|
+
//
|
211
|
+
alpha.setbounds(0, 1);
|
212
|
+
beta.setbounds(0, 2);
|
213
|
+
alpha(0) = 0;
|
214
|
+
alpha(1) = 0;
|
215
|
+
for(i = 0; i <= 2; i++)
|
216
|
+
{
|
217
|
+
beta(i) = ap::sqr(double(i))/(4*ap::sqr(double(i))-1);
|
218
|
+
}
|
219
|
+
generategaussradauquadrature(alpha, beta, 2.0, double(+1), 3, x, w);
|
220
|
+
err = 0;
|
221
|
+
err = ap::maxreal(err, fabs(x(2)-1));
|
222
|
+
err = ap::maxreal(err, fabs(x(1)+(1-sqrt(double(6)))/5));
|
223
|
+
err = ap::maxreal(err, fabs(x(0)+(1+sqrt(double(6)))/5));
|
224
|
+
err = ap::maxreal(err, fabs(w(2)-double(2)/double(9)));
|
225
|
+
err = ap::maxreal(err, fabs(w(1)-(16+sqrt(double(6)))/18));
|
226
|
+
err = ap::maxreal(err, fabs(w(0)-(16-sqrt(double(6)))/18));
|
227
|
+
printf("Second test (Gauss-Radau 3, at point b): error is %6.3le\n",
|
228
|
+
double(err));
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
- Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer listed
|
13
|
+
in this license in the documentation and/or other materials
|
14
|
+
provided with the distribution.
|
15
|
+
|
16
|
+
- Neither the name of the copyright holders nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*************************************************************************/
|
32
|
+
|
33
|
+
#ifndef _gqgenradau_h
|
34
|
+
#define _gqgenradau_h
|
35
|
+
|
36
|
+
#include "ap.h"
|
37
|
+
#include "ialglib.h"
|
38
|
+
|
39
|
+
#include "blas.h"
|
40
|
+
#include "rotations.h"
|
41
|
+
#include "tdevd.h"
|
42
|
+
|
43
|
+
|
44
|
+
/*************************************************************************
|
45
|
+
Computation of nodes and weights for a Gauss-Radua quadrature formula
|
46
|
+
|
47
|
+
The algorithm generates the N-point Gauss-Radau quadrature formula with
|
48
|
+
weight function given by the coefficients alpha and beta of a recurrence
|
49
|
+
which generates a system of orthogonal polynomials.
|
50
|
+
|
51
|
+
P-1(x) = 0
|
52
|
+
P0(x) = 1
|
53
|
+
Pn+1(x) = (x-alpha(n))*Pn(x) - beta(n)*Pn-1(x)
|
54
|
+
|
55
|
+
and zero moment Mu0
|
56
|
+
|
57
|
+
Mu0 = integral(W(x)dx,a,b)
|
58
|
+
|
59
|
+
|
60
|
+
Input parameters:
|
61
|
+
Alpha � array of coefficients.
|
62
|
+
Array whose index ranges within [0..N-2].
|
63
|
+
Beta � array of coefficients.
|
64
|
+
Array whose index ranges within [0..N-1].
|
65
|
+
Zero-indexed element is not used.
|
66
|
+
Beta[I]>0
|
67
|
+
Mu0 � zero moment of the weighting function.
|
68
|
+
A � left boundary of the integration interval.
|
69
|
+
N � number of nodes of the quadrature formula, N>=2
|
70
|
+
(including the left boundary node).
|
71
|
+
|
72
|
+
Output parameters:
|
73
|
+
X � array of nodes of the quadrature formula (in ascending order).
|
74
|
+
Array whose index ranges within [0..N-1].
|
75
|
+
W � array of weights of the quadrature formula.
|
76
|
+
Array whose index ranges within [0..N-1].
|
77
|
+
|
78
|
+
Result:
|
79
|
+
True, if the algorithm finished its work successfully.
|
80
|
+
False, if the algorithm of finding eigenvalues has not converged, or
|
81
|
+
one or more of the Beta coefficients is less or equal to 0.
|
82
|
+
|
83
|
+
-- ALGLIB --
|
84
|
+
Copyright 2005 by Bochkanov Sergey
|
85
|
+
*************************************************************************/
|
86
|
+
bool generategaussradauquadrature(ap::real_1d_array alpha,
|
87
|
+
ap::real_1d_array beta,
|
88
|
+
double mu0,
|
89
|
+
double a,
|
90
|
+
int n,
|
91
|
+
ap::real_1d_array& x,
|
92
|
+
ap::real_1d_array& w);
|
93
|
+
|
94
|
+
|
95
|
+
#endif
|
@@ -0,0 +1,480 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
- Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer listed
|
13
|
+
in this license in the documentation and/or other materials
|
14
|
+
provided with the distribution.
|
15
|
+
|
16
|
+
- Neither the name of the copyright holders nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*************************************************************************/
|
32
|
+
|
33
|
+
#include <stdafx.h>
|
34
|
+
#include "hbisinv.h"
|
35
|
+
|
36
|
+
/*************************************************************************
|
37
|
+
Subroutine for finding the eigenvalues (and eigenvectors) of a Hermitian
|
38
|
+
matrix in a given half-interval (A, B] by using a bisection and inverse
|
39
|
+
iteration
|
40
|
+
|
41
|
+
Input parameters:
|
42
|
+
A - Hermitian matrix which is given by its upper or lower
|
43
|
+
triangular part. Array whose indexes range within
|
44
|
+
[0..N-1, 0..N-1].
|
45
|
+
N - size of matrix A.
|
46
|
+
ZNeeded - flag controlling whether the eigenvectors are needed or
|
47
|
+
not. If ZNeeded is equal to:
|
48
|
+
* 0, the eigenvectors are not returned;
|
49
|
+
* 1, the eigenvectors are returned.
|
50
|
+
IsUpperA - storage format of matrix A.
|
51
|
+
B1, B2 - half-interval (B1, B2] to search eigenvalues in.
|
52
|
+
|
53
|
+
Output parameters:
|
54
|
+
M - number of eigenvalues found in a given half-interval, M>=0
|
55
|
+
W - array of the eigenvalues found.
|
56
|
+
Array whose index ranges within [0..M-1].
|
57
|
+
Z - if ZNeeded is equal to:
|
58
|
+
* 0, Z hasn�t changed;
|
59
|
+
* 1, Z contains eigenvectors.
|
60
|
+
Array whose indexes range within [0..N-1, 0..M-1].
|
61
|
+
The eigenvectors are stored in the matrix columns.
|
62
|
+
|
63
|
+
Result:
|
64
|
+
True, if successful. M contains the number of eigenvalues in the given
|
65
|
+
half-interval (could be equal to 0), W contains the eigenvalues,
|
66
|
+
Z contains the eigenvectors (if needed).
|
67
|
+
|
68
|
+
False, if the bisection method subroutine wasn't able to find the
|
69
|
+
eigenvalues in the given interval or if the inverse iteration
|
70
|
+
subroutine wasn't able to find all the corresponding eigenvectors.
|
71
|
+
In that case, the eigenvalues and eigenvectors are not returned, M is
|
72
|
+
equal to 0.
|
73
|
+
|
74
|
+
Note:
|
75
|
+
eigen vectors of Hermitian matrix are defined up to multiplication by
|
76
|
+
a complex number L, such as |L|=1.
|
77
|
+
|
78
|
+
-- ALGLIB --
|
79
|
+
Copyright 07.01.2006, 24.03.2007 by Bochkanov Sergey.
|
80
|
+
*************************************************************************/
|
81
|
+
bool hmatrixevdr(ap::complex_2d_array a,
|
82
|
+
int n,
|
83
|
+
int zneeded,
|
84
|
+
bool isupper,
|
85
|
+
double b1,
|
86
|
+
double b2,
|
87
|
+
int& m,
|
88
|
+
ap::real_1d_array& w,
|
89
|
+
ap::complex_2d_array& z)
|
90
|
+
{
|
91
|
+
bool result;
|
92
|
+
ap::complex_2d_array q;
|
93
|
+
ap::real_2d_array t;
|
94
|
+
ap::complex_1d_array tau;
|
95
|
+
ap::real_1d_array e;
|
96
|
+
ap::real_1d_array work;
|
97
|
+
int i;
|
98
|
+
int k;
|
99
|
+
double v;
|
100
|
+
|
101
|
+
ap::ap_error::make_assertion(zneeded==0||zneeded==1, "HermitianEigenValuesAndVectorsInInterval: incorrect ZNeeded");
|
102
|
+
|
103
|
+
//
|
104
|
+
// Reduce to tridiagonal form
|
105
|
+
//
|
106
|
+
hmatrixtd(a, n, isupper, tau, w, e);
|
107
|
+
if( zneeded==1 )
|
108
|
+
{
|
109
|
+
hmatrixtdunpackq(a, n, isupper, tau, q);
|
110
|
+
zneeded = 2;
|
111
|
+
}
|
112
|
+
|
113
|
+
//
|
114
|
+
// Bisection and inverse iteration
|
115
|
+
//
|
116
|
+
result = smatrixtdevdr(w, e, n, zneeded, b1, b2, m, t);
|
117
|
+
|
118
|
+
//
|
119
|
+
// Eigenvectors are needed
|
120
|
+
// Calculate Z = Q*T = Re(Q)*T + i*Im(Q)*T
|
121
|
+
//
|
122
|
+
if( result&&zneeded!=0&&m!=0 )
|
123
|
+
{
|
124
|
+
work.setbounds(0, m-1);
|
125
|
+
z.setbounds(0, n-1, 0, m-1);
|
126
|
+
for(i = 0; i <= n-1; i++)
|
127
|
+
{
|
128
|
+
|
129
|
+
//
|
130
|
+
// Calculate real part
|
131
|
+
//
|
132
|
+
for(k = 0; k <= m-1; k++)
|
133
|
+
{
|
134
|
+
work(k) = 0;
|
135
|
+
}
|
136
|
+
for(k = 0; k <= n-1; k++)
|
137
|
+
{
|
138
|
+
v = q(i,k).x;
|
139
|
+
ap::vadd(&work(0), &t(k, 0), ap::vlen(0,m-1), v);
|
140
|
+
}
|
141
|
+
for(k = 0; k <= m-1; k++)
|
142
|
+
{
|
143
|
+
z(i,k).x = work(k);
|
144
|
+
}
|
145
|
+
|
146
|
+
//
|
147
|
+
// Calculate imaginary part
|
148
|
+
//
|
149
|
+
for(k = 0; k <= m-1; k++)
|
150
|
+
{
|
151
|
+
work(k) = 0;
|
152
|
+
}
|
153
|
+
for(k = 0; k <= n-1; k++)
|
154
|
+
{
|
155
|
+
v = q(i,k).y;
|
156
|
+
ap::vadd(&work(0), &t(k, 0), ap::vlen(0,m-1), v);
|
157
|
+
}
|
158
|
+
for(k = 0; k <= m-1; k++)
|
159
|
+
{
|
160
|
+
z(i,k).y = work(k);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
return result;
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
/*************************************************************************
|
169
|
+
Subroutine for finding the eigenvalues and eigenvectors of a Hermitian
|
170
|
+
matrix with given indexes by using bisection and inverse iteration methods
|
171
|
+
|
172
|
+
Input parameters:
|
173
|
+
A - Hermitian matrix which is given by its upper or lower
|
174
|
+
triangular part.
|
175
|
+
Array whose indexes range within [0..N-1, 0..N-1].
|
176
|
+
N - size of matrix A.
|
177
|
+
ZNeeded - flag controlling whether the eigenvectors are needed or
|
178
|
+
not. If ZNeeded is equal to:
|
179
|
+
* 0, the eigenvectors are not returned;
|
180
|
+
* 1, the eigenvectors are returned.
|
181
|
+
IsUpperA - storage format of matrix A.
|
182
|
+
I1, I2 - index interval for searching (from I1 to I2).
|
183
|
+
0 <= I1 <= I2 <= N-1.
|
184
|
+
|
185
|
+
Output parameters:
|
186
|
+
W - array of the eigenvalues found.
|
187
|
+
Array whose index ranges within [0..I2-I1].
|
188
|
+
Z - if ZNeeded is equal to:
|
189
|
+
* 0, Z hasn�t changed;
|
190
|
+
* 1, Z contains eigenvectors.
|
191
|
+
Array whose indexes range within [0..N-1, 0..I2-I1].
|
192
|
+
In that case, the eigenvectors are stored in the matrix
|
193
|
+
columns.
|
194
|
+
|
195
|
+
Result:
|
196
|
+
True, if successful. W contains the eigenvalues, Z contains the
|
197
|
+
eigenvectors (if needed).
|
198
|
+
|
199
|
+
False, if the bisection method subroutine wasn't able to find the
|
200
|
+
eigenvalues in the given interval or if the inverse iteration
|
201
|
+
subroutine wasn't able to find all the corresponding eigenvectors.
|
202
|
+
In that case, the eigenvalues and eigenvectors are not returned.
|
203
|
+
|
204
|
+
Note:
|
205
|
+
eigen vectors of Hermitian matrix are defined up to multiplication by
|
206
|
+
a complex number L, such as |L|=1.
|
207
|
+
|
208
|
+
-- ALGLIB --
|
209
|
+
Copyright 07.01.2006, 24.03.2007 by Bochkanov Sergey.
|
210
|
+
*************************************************************************/
|
211
|
+
bool hmatrixevdi(ap::complex_2d_array a,
|
212
|
+
int n,
|
213
|
+
int zneeded,
|
214
|
+
bool isupper,
|
215
|
+
int i1,
|
216
|
+
int i2,
|
217
|
+
ap::real_1d_array& w,
|
218
|
+
ap::complex_2d_array& z)
|
219
|
+
{
|
220
|
+
bool result;
|
221
|
+
ap::complex_2d_array q;
|
222
|
+
ap::real_2d_array t;
|
223
|
+
ap::complex_1d_array tau;
|
224
|
+
ap::real_1d_array e;
|
225
|
+
ap::real_1d_array work;
|
226
|
+
int i;
|
227
|
+
int k;
|
228
|
+
double v;
|
229
|
+
int m;
|
230
|
+
|
231
|
+
ap::ap_error::make_assertion(zneeded==0||zneeded==1, "HermitianEigenValuesAndVectorsByIndexes: incorrect ZNeeded");
|
232
|
+
|
233
|
+
//
|
234
|
+
// Reduce to tridiagonal form
|
235
|
+
//
|
236
|
+
hmatrixtd(a, n, isupper, tau, w, e);
|
237
|
+
if( zneeded==1 )
|
238
|
+
{
|
239
|
+
hmatrixtdunpackq(a, n, isupper, tau, q);
|
240
|
+
zneeded = 2;
|
241
|
+
}
|
242
|
+
|
243
|
+
//
|
244
|
+
// Bisection and inverse iteration
|
245
|
+
//
|
246
|
+
result = smatrixtdevdi(w, e, n, zneeded, i1, i2, t);
|
247
|
+
|
248
|
+
//
|
249
|
+
// Eigenvectors are needed
|
250
|
+
// Calculate Z = Q*T = Re(Q)*T + i*Im(Q)*T
|
251
|
+
//
|
252
|
+
m = i2-i1+1;
|
253
|
+
if( result&&zneeded!=0 )
|
254
|
+
{
|
255
|
+
work.setbounds(0, m-1);
|
256
|
+
z.setbounds(0, n-1, 0, m-1);
|
257
|
+
for(i = 0; i <= n-1; i++)
|
258
|
+
{
|
259
|
+
|
260
|
+
//
|
261
|
+
// Calculate real part
|
262
|
+
//
|
263
|
+
for(k = 0; k <= m-1; k++)
|
264
|
+
{
|
265
|
+
work(k) = 0;
|
266
|
+
}
|
267
|
+
for(k = 0; k <= n-1; k++)
|
268
|
+
{
|
269
|
+
v = q(i,k).x;
|
270
|
+
ap::vadd(&work(0), &t(k, 0), ap::vlen(0,m-1), v);
|
271
|
+
}
|
272
|
+
for(k = 0; k <= m-1; k++)
|
273
|
+
{
|
274
|
+
z(i,k).x = work(k);
|
275
|
+
}
|
276
|
+
|
277
|
+
//
|
278
|
+
// Calculate imaginary part
|
279
|
+
//
|
280
|
+
for(k = 0; k <= m-1; k++)
|
281
|
+
{
|
282
|
+
work(k) = 0;
|
283
|
+
}
|
284
|
+
for(k = 0; k <= n-1; k++)
|
285
|
+
{
|
286
|
+
v = q(i,k).y;
|
287
|
+
ap::vadd(&work(0), &t(k, 0), ap::vlen(0,m-1), v);
|
288
|
+
}
|
289
|
+
for(k = 0; k <= m-1; k++)
|
290
|
+
{
|
291
|
+
z(i,k).y = work(k);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
return result;
|
296
|
+
}
|
297
|
+
|
298
|
+
|
299
|
+
/*************************************************************************
|
300
|
+
Obsolete 1-based subroutine
|
301
|
+
*************************************************************************/
|
302
|
+
bool hermitianeigenvaluesandvectorsininterval(ap::complex_2d_array a,
|
303
|
+
int n,
|
304
|
+
int zneeded,
|
305
|
+
bool isupper,
|
306
|
+
double b1,
|
307
|
+
double b2,
|
308
|
+
int& m,
|
309
|
+
ap::real_1d_array& w,
|
310
|
+
ap::complex_2d_array& z)
|
311
|
+
{
|
312
|
+
bool result;
|
313
|
+
ap::complex_2d_array q;
|
314
|
+
ap::real_2d_array t;
|
315
|
+
ap::complex_1d_array tau;
|
316
|
+
ap::real_1d_array e;
|
317
|
+
ap::real_1d_array work;
|
318
|
+
int i;
|
319
|
+
int k;
|
320
|
+
double v;
|
321
|
+
|
322
|
+
ap::ap_error::make_assertion(zneeded==0||zneeded==1, "HermitianEigenValuesAndVectorsInInterval: incorrect ZNeeded");
|
323
|
+
|
324
|
+
//
|
325
|
+
// Reduce to tridiagonal form
|
326
|
+
//
|
327
|
+
hermitiantotridiagonal(a, n, isupper, tau, w, e);
|
328
|
+
if( zneeded==1 )
|
329
|
+
{
|
330
|
+
unpackqfromhermitiantridiagonal(a, n, isupper, tau, q);
|
331
|
+
zneeded = 2;
|
332
|
+
}
|
333
|
+
|
334
|
+
//
|
335
|
+
// Bisection and inverse iteration
|
336
|
+
//
|
337
|
+
result = tridiagonaleigenvaluesandvectorsininterval(w, e, n, zneeded, b1, b2, m, t);
|
338
|
+
|
339
|
+
//
|
340
|
+
// Eigenvectors are needed
|
341
|
+
// Calculate Z = Q*T = Re(Q)*T + i*Im(Q)*T
|
342
|
+
//
|
343
|
+
if( result&&zneeded!=0&&m!=0 )
|
344
|
+
{
|
345
|
+
work.setbounds(1, m);
|
346
|
+
z.setbounds(1, n, 1, m);
|
347
|
+
for(i = 1; i <= n; i++)
|
348
|
+
{
|
349
|
+
|
350
|
+
//
|
351
|
+
// Calculate real part
|
352
|
+
//
|
353
|
+
for(k = 1; k <= m; k++)
|
354
|
+
{
|
355
|
+
work(k) = 0;
|
356
|
+
}
|
357
|
+
for(k = 1; k <= n; k++)
|
358
|
+
{
|
359
|
+
v = q(i,k).x;
|
360
|
+
ap::vadd(&work(1), &t(k, 1), ap::vlen(1,m), v);
|
361
|
+
}
|
362
|
+
for(k = 1; k <= m; k++)
|
363
|
+
{
|
364
|
+
z(i,k).x = work(k);
|
365
|
+
}
|
366
|
+
|
367
|
+
//
|
368
|
+
// Calculate imaginary part
|
369
|
+
//
|
370
|
+
for(k = 1; k <= m; k++)
|
371
|
+
{
|
372
|
+
work(k) = 0;
|
373
|
+
}
|
374
|
+
for(k = 1; k <= n; k++)
|
375
|
+
{
|
376
|
+
v = q(i,k).y;
|
377
|
+
ap::vadd(&work(1), &t(k, 1), ap::vlen(1,m), v);
|
378
|
+
}
|
379
|
+
for(k = 1; k <= m; k++)
|
380
|
+
{
|
381
|
+
z(i,k).y = work(k);
|
382
|
+
}
|
383
|
+
}
|
384
|
+
}
|
385
|
+
return result;
|
386
|
+
}
|
387
|
+
|
388
|
+
|
389
|
+
/*************************************************************************
|
390
|
+
Obsolete 1-based subroutine
|
391
|
+
*************************************************************************/
|
392
|
+
bool hermitianeigenvaluesandvectorsbyindexes(ap::complex_2d_array a,
|
393
|
+
int n,
|
394
|
+
int zneeded,
|
395
|
+
bool isupper,
|
396
|
+
int i1,
|
397
|
+
int i2,
|
398
|
+
ap::real_1d_array& w,
|
399
|
+
ap::complex_2d_array& z)
|
400
|
+
{
|
401
|
+
bool result;
|
402
|
+
ap::complex_2d_array q;
|
403
|
+
ap::real_2d_array t;
|
404
|
+
ap::complex_1d_array tau;
|
405
|
+
ap::real_1d_array e;
|
406
|
+
ap::real_1d_array work;
|
407
|
+
int i;
|
408
|
+
int k;
|
409
|
+
double v;
|
410
|
+
int m;
|
411
|
+
|
412
|
+
ap::ap_error::make_assertion(zneeded==0||zneeded==1, "HermitianEigenValuesAndVectorsByIndexes: incorrect ZNeeded");
|
413
|
+
|
414
|
+
//
|
415
|
+
// Reduce to tridiagonal form
|
416
|
+
//
|
417
|
+
hermitiantotridiagonal(a, n, isupper, tau, w, e);
|
418
|
+
if( zneeded==1 )
|
419
|
+
{
|
420
|
+
unpackqfromhermitiantridiagonal(a, n, isupper, tau, q);
|
421
|
+
zneeded = 2;
|
422
|
+
}
|
423
|
+
|
424
|
+
//
|
425
|
+
// Bisection and inverse iteration
|
426
|
+
//
|
427
|
+
result = tridiagonaleigenvaluesandvectorsbyindexes(w, e, n, zneeded, i1, i2, t);
|
428
|
+
|
429
|
+
//
|
430
|
+
// Eigenvectors are needed
|
431
|
+
// Calculate Z = Q*T = Re(Q)*T + i*Im(Q)*T
|
432
|
+
//
|
433
|
+
m = i2-i1+1;
|
434
|
+
if( result&&zneeded!=0 )
|
435
|
+
{
|
436
|
+
work.setbounds(1, m);
|
437
|
+
z.setbounds(1, n, 1, m);
|
438
|
+
for(i = 1; i <= n; i++)
|
439
|
+
{
|
440
|
+
|
441
|
+
//
|
442
|
+
// Calculate real part
|
443
|
+
//
|
444
|
+
for(k = 1; k <= m; k++)
|
445
|
+
{
|
446
|
+
work(k) = 0;
|
447
|
+
}
|
448
|
+
for(k = 1; k <= n; k++)
|
449
|
+
{
|
450
|
+
v = q(i,k).x;
|
451
|
+
ap::vadd(&work(1), &t(k, 1), ap::vlen(1,m), v);
|
452
|
+
}
|
453
|
+
for(k = 1; k <= m; k++)
|
454
|
+
{
|
455
|
+
z(i,k).x = work(k);
|
456
|
+
}
|
457
|
+
|
458
|
+
//
|
459
|
+
// Calculate imaginary part
|
460
|
+
//
|
461
|
+
for(k = 1; k <= m; k++)
|
462
|
+
{
|
463
|
+
work(k) = 0;
|
464
|
+
}
|
465
|
+
for(k = 1; k <= n; k++)
|
466
|
+
{
|
467
|
+
v = q(i,k).y;
|
468
|
+
ap::vadd(&work(1), &t(k, 1), ap::vlen(1,m), v);
|
469
|
+
}
|
470
|
+
for(k = 1; k <= m; k++)
|
471
|
+
{
|
472
|
+
z(i,k).y = work(k);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
}
|
476
|
+
return result;
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
|