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,134 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 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 _correlationtests_h
|
34
|
+
#define _correlationtests_h
|
35
|
+
|
36
|
+
#include "ap.h"
|
37
|
+
#include "ialglib.h"
|
38
|
+
|
39
|
+
#include "gammaf.h"
|
40
|
+
#include "normaldistr.h"
|
41
|
+
#include "ibetaf.h"
|
42
|
+
#include "studenttdistr.h"
|
43
|
+
#include "correlation.h"
|
44
|
+
|
45
|
+
|
46
|
+
/*************************************************************************
|
47
|
+
Pearson's correlation coefficient significance test
|
48
|
+
|
49
|
+
This test checks hypotheses about whether X and Y are samples of two
|
50
|
+
continuous distributions having zero correlation or whether their
|
51
|
+
correlation is non-zero.
|
52
|
+
|
53
|
+
The following tests are performed:
|
54
|
+
* two-tailed test (null hypothesis - X and Y have zero correlation)
|
55
|
+
* left-tailed test (null hypothesis - the correlation coefficient is
|
56
|
+
greater than or equal to 0)
|
57
|
+
* right-tailed test (null hypothesis - the correlation coefficient is
|
58
|
+
less than or equal to 0).
|
59
|
+
|
60
|
+
Requirements:
|
61
|
+
* the number of elements in each sample is not less than 5
|
62
|
+
* normality of distributions of X and Y.
|
63
|
+
|
64
|
+
Input parameters:
|
65
|
+
R - Pearson's correlation coefficient for X and Y
|
66
|
+
N - number of elements in samples, N>=5.
|
67
|
+
|
68
|
+
Output parameters:
|
69
|
+
BothTails - p-value for two-tailed test.
|
70
|
+
If BothTails is less than the given significance level
|
71
|
+
the null hypothesis is rejected.
|
72
|
+
LeftTail - p-value for left-tailed test.
|
73
|
+
If LeftTail is less than the given significance level,
|
74
|
+
the null hypothesis is rejected.
|
75
|
+
RightTail - p-value for right-tailed test.
|
76
|
+
If RightTail is less than the given significance level
|
77
|
+
the null hypothesis is rejected.
|
78
|
+
|
79
|
+
-- ALGLIB --
|
80
|
+
Copyright 09.04.2007 by Bochkanov Sergey
|
81
|
+
*************************************************************************/
|
82
|
+
void pearsoncorrelationsignificance(double r,
|
83
|
+
int n,
|
84
|
+
double& bothtails,
|
85
|
+
double& lefttail,
|
86
|
+
double& righttail);
|
87
|
+
|
88
|
+
|
89
|
+
/*************************************************************************
|
90
|
+
Spearman's rank correlation coefficient significance test
|
91
|
+
|
92
|
+
This test checks hypotheses about whether X and Y are samples of two
|
93
|
+
continuous distributions having zero correlation or whether their
|
94
|
+
correlation is non-zero.
|
95
|
+
|
96
|
+
The following tests are performed:
|
97
|
+
* two-tailed test (null hypothesis - X and Y have zero correlation)
|
98
|
+
* left-tailed test (null hypothesis - the correlation coefficient is
|
99
|
+
greater than or equal to 0)
|
100
|
+
* right-tailed test (null hypothesis - the correlation coefficient is
|
101
|
+
less than or equal to 0).
|
102
|
+
|
103
|
+
Requirements:
|
104
|
+
* the number of elements in each sample is not less than 5.
|
105
|
+
|
106
|
+
The test is non-parametric and doesn't require distributions X and Y to be
|
107
|
+
normal.
|
108
|
+
|
109
|
+
Input parameters:
|
110
|
+
R - Spearman's rank correlation coefficient for X and Y
|
111
|
+
N - number of elements in samples, N>=5.
|
112
|
+
|
113
|
+
Output parameters:
|
114
|
+
BothTails - p-value for two-tailed test.
|
115
|
+
If BothTails is less than the given significance level
|
116
|
+
the null hypothesis is rejected.
|
117
|
+
LeftTail - p-value for left-tailed test.
|
118
|
+
If LeftTail is less than the given significance level,
|
119
|
+
the null hypothesis is rejected.
|
120
|
+
RightTail - p-value for right-tailed test.
|
121
|
+
If RightTail is less than the given significance level
|
122
|
+
the null hypothesis is rejected.
|
123
|
+
|
124
|
+
-- ALGLIB --
|
125
|
+
Copyright 09.04.2007 by Bochkanov Sergey
|
126
|
+
*************************************************************************/
|
127
|
+
void spearmanrankcorrelationsignificance(double r,
|
128
|
+
int n,
|
129
|
+
double& bothtails,
|
130
|
+
double& lefttail,
|
131
|
+
double& righttail);
|
132
|
+
|
133
|
+
|
134
|
+
#endif
|
@@ -0,0 +1,826 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 1992-2007 The University of Tennessee. All rights reserved.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Sergey Bochkanov (ALGLIB project). Translation from FORTRAN to
|
6
|
+
pseudocode.
|
7
|
+
|
8
|
+
See subroutines comments for additional copyrights.
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions are
|
12
|
+
met:
|
13
|
+
|
14
|
+
- Redistributions of source code must retain the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
16
|
+
|
17
|
+
- Redistributions in binary form must reproduce the above copyright
|
18
|
+
notice, this list of conditions and the following disclaimer listed
|
19
|
+
in this license in the documentation and/or other materials
|
20
|
+
provided with the distribution.
|
21
|
+
|
22
|
+
- Neither the name of the copyright holders nor the names of its
|
23
|
+
contributors may be used to endorse or promote products derived from
|
24
|
+
this software without specific prior written permission.
|
25
|
+
|
26
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
27
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
28
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
29
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
30
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
31
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
32
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
33
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
34
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
35
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
36
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
37
|
+
*************************************************************************/
|
38
|
+
|
39
|
+
#include <stdafx.h>
|
40
|
+
#include "crcond.h"
|
41
|
+
|
42
|
+
static void internalcomplexrcondestimatenorm(const int& n,
|
43
|
+
ap::complex_1d_array& v,
|
44
|
+
ap::complex_1d_array& x,
|
45
|
+
double& est,
|
46
|
+
int& kase,
|
47
|
+
ap::integer_1d_array& isave,
|
48
|
+
ap::real_1d_array& rsave);
|
49
|
+
static double internalcomplexrcondscsum1(const ap::complex_1d_array& x, int n);
|
50
|
+
static int internalcomplexrcondicmax1(const ap::complex_1d_array& x, int n);
|
51
|
+
static void internalcomplexrcondsaveall(ap::integer_1d_array& isave,
|
52
|
+
ap::real_1d_array& rsave,
|
53
|
+
int& i,
|
54
|
+
int& iter,
|
55
|
+
int& j,
|
56
|
+
int& jlast,
|
57
|
+
int& jump,
|
58
|
+
double& absxi,
|
59
|
+
double& altsgn,
|
60
|
+
double& estold,
|
61
|
+
double& temp);
|
62
|
+
static void internalcomplexrcondloadall(ap::integer_1d_array& isave,
|
63
|
+
ap::real_1d_array& rsave,
|
64
|
+
int& i,
|
65
|
+
int& iter,
|
66
|
+
int& j,
|
67
|
+
int& jlast,
|
68
|
+
int& jump,
|
69
|
+
double& absxi,
|
70
|
+
double& altsgn,
|
71
|
+
double& estold,
|
72
|
+
double& temp);
|
73
|
+
|
74
|
+
/*************************************************************************
|
75
|
+
Estimate of a matrix condition number (1-norm)
|
76
|
+
|
77
|
+
The algorithm calculates a lower bound of the condition number. In this case,
|
78
|
+
the algorithm does not return a lower bound of the condition number, but an
|
79
|
+
inverse number (to avoid an overflow in case of a singular matrix).
|
80
|
+
|
81
|
+
Input parameters:
|
82
|
+
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
|
83
|
+
N - size of matrix A.
|
84
|
+
|
85
|
+
Result: 1/LowerBound(cond(A))
|
86
|
+
*************************************************************************/
|
87
|
+
double cmatrixrcond1(const ap::complex_2d_array& a, int n)
|
88
|
+
{
|
89
|
+
double result;
|
90
|
+
int i;
|
91
|
+
ap::complex_2d_array a1;
|
92
|
+
int i_;
|
93
|
+
int i1_;
|
94
|
+
|
95
|
+
ap::ap_error::make_assertion(n>=1, "CMatrixRCond1: N<1!");
|
96
|
+
a1.setbounds(1, n, 1, n);
|
97
|
+
for(i = 1; i <= n; i++)
|
98
|
+
{
|
99
|
+
i1_ = (0) - (1);
|
100
|
+
for(i_=1; i_<=n;i_++)
|
101
|
+
{
|
102
|
+
a1(i,i_) = a(i-1,i_+i1_);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
result = complexrcond1(a1, n);
|
106
|
+
return result;
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
/*************************************************************************
|
111
|
+
Estimate of the condition number of a matrix given by its LU decomposition (1-norm)
|
112
|
+
|
113
|
+
The algorithm calculates a lower bound of the condition number. In this case,
|
114
|
+
the algorithm does not return a lower bound of the condition number, but an
|
115
|
+
inverse number (to avoid an overflow in case of a singular matrix).
|
116
|
+
|
117
|
+
Input parameters:
|
118
|
+
LUDcmp - LU decomposition of a matrix in compact form. Output of
|
119
|
+
the CMatrixLU subroutine.
|
120
|
+
N - size of matrix A.
|
121
|
+
|
122
|
+
Result: 1/LowerBound(cond(A))
|
123
|
+
*************************************************************************/
|
124
|
+
double cmatrixlurcond1(const ap::complex_2d_array& ludcmp, int n)
|
125
|
+
{
|
126
|
+
double result;
|
127
|
+
int i;
|
128
|
+
ap::complex_2d_array a1;
|
129
|
+
int i_;
|
130
|
+
int i1_;
|
131
|
+
|
132
|
+
ap::ap_error::make_assertion(n>=1, "CMatrixLURCond1: N<1!");
|
133
|
+
a1.setbounds(1, n, 1, n);
|
134
|
+
for(i = 1; i <= n; i++)
|
135
|
+
{
|
136
|
+
i1_ = (0) - (1);
|
137
|
+
for(i_=1; i_<=n;i_++)
|
138
|
+
{
|
139
|
+
a1(i,i_) = ludcmp(i-1,i_+i1_);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
result = complexrcond1lu(a1, n);
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
|
147
|
+
/*************************************************************************
|
148
|
+
Estimate of a matrix condition number (infinity-norm).
|
149
|
+
|
150
|
+
The algorithm calculates a lower bound of the condition number. In this case,
|
151
|
+
the algorithm does not return a lower bound of the condition number, but an
|
152
|
+
inverse number (to avoid an overflow in case of a singular matrix).
|
153
|
+
|
154
|
+
Input parameters:
|
155
|
+
A - matrix. Array whose indexes range within [0..N-1, 0..N-1].
|
156
|
+
N - size of matrix A.
|
157
|
+
|
158
|
+
Result: 1/LowerBound(cond(A))
|
159
|
+
*************************************************************************/
|
160
|
+
double cmatrixrcondinf(const ap::complex_2d_array& a, int n)
|
161
|
+
{
|
162
|
+
double result;
|
163
|
+
int i;
|
164
|
+
ap::complex_2d_array a1;
|
165
|
+
int i_;
|
166
|
+
int i1_;
|
167
|
+
|
168
|
+
ap::ap_error::make_assertion(n>=1, "CMatrixRCondInf: N<1!");
|
169
|
+
a1.setbounds(1, n, 1, n);
|
170
|
+
for(i = 1; i <= n; i++)
|
171
|
+
{
|
172
|
+
i1_ = (0) - (1);
|
173
|
+
for(i_=1; i_<=n;i_++)
|
174
|
+
{
|
175
|
+
a1(i,i_) = a(i-1,i_+i1_);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
result = complexrcondinf(a1, n);
|
179
|
+
return result;
|
180
|
+
}
|
181
|
+
|
182
|
+
|
183
|
+
/*************************************************************************
|
184
|
+
Estimate of the condition number of a matrix given by its LU decomposition
|
185
|
+
(infinity norm).
|
186
|
+
|
187
|
+
The algorithm calculates a lower bound of the condition number. In this case,
|
188
|
+
the algorithm does not return a lower bound of the condition number, but an
|
189
|
+
inverse number (to avoid an overflow in case of a singular matrix).
|
190
|
+
|
191
|
+
Input parameters:
|
192
|
+
LUDcmp - LU decomposition of a matrix in compact form. Output of
|
193
|
+
the CMatrixLU subroutine.
|
194
|
+
N - size of matrix A.
|
195
|
+
|
196
|
+
Result: 1/LowerBound(cond(A))
|
197
|
+
*************************************************************************/
|
198
|
+
double cmatrixlurcondinf(const ap::complex_2d_array& ludcmp, int n)
|
199
|
+
{
|
200
|
+
double result;
|
201
|
+
int i;
|
202
|
+
ap::complex_2d_array a1;
|
203
|
+
int i_;
|
204
|
+
int i1_;
|
205
|
+
|
206
|
+
ap::ap_error::make_assertion(n>=1, "CMatrixLURCondInf: N<1!");
|
207
|
+
a1.setbounds(1, n, 1, n);
|
208
|
+
for(i = 1; i <= n; i++)
|
209
|
+
{
|
210
|
+
i1_ = (0) - (1);
|
211
|
+
for(i_=1; i_<=n;i_++)
|
212
|
+
{
|
213
|
+
a1(i,i_) = ludcmp(i-1,i_+i1_);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
result = complexrcondinflu(a1, n);
|
217
|
+
return result;
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
/*************************************************************************
|
222
|
+
Obsolete 1-based subroutine.
|
223
|
+
*************************************************************************/
|
224
|
+
double complexrcond1(ap::complex_2d_array a, int n)
|
225
|
+
{
|
226
|
+
double result;
|
227
|
+
int i;
|
228
|
+
int j;
|
229
|
+
double v;
|
230
|
+
double nrm;
|
231
|
+
ap::integer_1d_array pivots;
|
232
|
+
|
233
|
+
nrm = 0;
|
234
|
+
for(j = 1; j <= n; j++)
|
235
|
+
{
|
236
|
+
v = 0;
|
237
|
+
for(i = 1; i <= n; i++)
|
238
|
+
{
|
239
|
+
v = v+ap::abscomplex(a(i,j));
|
240
|
+
}
|
241
|
+
nrm = ap::maxreal(nrm, v);
|
242
|
+
}
|
243
|
+
complexludecomposition(a, n, n, pivots);
|
244
|
+
internalestimatecomplexrcondlu(a, n, true, true, nrm, v);
|
245
|
+
result = v;
|
246
|
+
return result;
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
/*************************************************************************
|
251
|
+
Obsolete 1-based subroutine.
|
252
|
+
*************************************************************************/
|
253
|
+
double complexrcond1lu(const ap::complex_2d_array& lu, int n)
|
254
|
+
{
|
255
|
+
double result;
|
256
|
+
double v;
|
257
|
+
|
258
|
+
internalestimatecomplexrcondlu(lu, n, true, false, double(0), v);
|
259
|
+
result = v;
|
260
|
+
return result;
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
/*************************************************************************
|
265
|
+
Obsolete 1-based subroutine.
|
266
|
+
*************************************************************************/
|
267
|
+
double complexrcondinf(ap::complex_2d_array a, int n)
|
268
|
+
{
|
269
|
+
double result;
|
270
|
+
int i;
|
271
|
+
int j;
|
272
|
+
double v;
|
273
|
+
double nrm;
|
274
|
+
ap::integer_1d_array pivots;
|
275
|
+
|
276
|
+
nrm = 0;
|
277
|
+
for(i = 1; i <= n; i++)
|
278
|
+
{
|
279
|
+
v = 0;
|
280
|
+
for(j = 1; j <= n; j++)
|
281
|
+
{
|
282
|
+
v = v+ap::abscomplex(a(i,j));
|
283
|
+
}
|
284
|
+
nrm = ap::maxreal(nrm, v);
|
285
|
+
}
|
286
|
+
complexludecomposition(a, n, n, pivots);
|
287
|
+
internalestimatecomplexrcondlu(a, n, false, true, nrm, v);
|
288
|
+
result = v;
|
289
|
+
return result;
|
290
|
+
}
|
291
|
+
|
292
|
+
|
293
|
+
/*************************************************************************
|
294
|
+
Obsolete 1-based subroutine.
|
295
|
+
*************************************************************************/
|
296
|
+
double complexrcondinflu(const ap::complex_2d_array& lu, int n)
|
297
|
+
{
|
298
|
+
double result;
|
299
|
+
double v;
|
300
|
+
|
301
|
+
internalestimatecomplexrcondlu(lu, n, false, false, double(0), v);
|
302
|
+
result = v;
|
303
|
+
return result;
|
304
|
+
}
|
305
|
+
|
306
|
+
|
307
|
+
void internalestimatecomplexrcondlu(const ap::complex_2d_array& lu,
|
308
|
+
const int& n,
|
309
|
+
bool onenorm,
|
310
|
+
bool isanormprovided,
|
311
|
+
double anorm,
|
312
|
+
double& rcond)
|
313
|
+
{
|
314
|
+
ap::complex_1d_array cwork1;
|
315
|
+
ap::complex_1d_array cwork2;
|
316
|
+
ap::complex_1d_array cwork3;
|
317
|
+
ap::complex_1d_array cwork4;
|
318
|
+
ap::integer_1d_array isave;
|
319
|
+
ap::real_1d_array rsave;
|
320
|
+
int kase;
|
321
|
+
int kase1;
|
322
|
+
double ainvnm;
|
323
|
+
double smlnum;
|
324
|
+
bool cw;
|
325
|
+
ap::complex v;
|
326
|
+
int i;
|
327
|
+
int i_;
|
328
|
+
|
329
|
+
if( n<=0 )
|
330
|
+
{
|
331
|
+
return;
|
332
|
+
}
|
333
|
+
cwork1.setbounds(1, n);
|
334
|
+
cwork2.setbounds(1, n);
|
335
|
+
cwork3.setbounds(1, n);
|
336
|
+
cwork4.setbounds(1, n);
|
337
|
+
isave.setbounds(0, 4);
|
338
|
+
rsave.setbounds(0, 3);
|
339
|
+
rcond = 0;
|
340
|
+
if( n==0 )
|
341
|
+
{
|
342
|
+
rcond = 1;
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
smlnum = ap::minrealnumber;
|
346
|
+
|
347
|
+
//
|
348
|
+
// Estimate the norm of inv(A).
|
349
|
+
//
|
350
|
+
if( !isanormprovided )
|
351
|
+
{
|
352
|
+
anorm = 0;
|
353
|
+
if( onenorm )
|
354
|
+
{
|
355
|
+
kase1 = 1;
|
356
|
+
}
|
357
|
+
else
|
358
|
+
{
|
359
|
+
kase1 = 2;
|
360
|
+
}
|
361
|
+
kase = 0;
|
362
|
+
do
|
363
|
+
{
|
364
|
+
internalcomplexrcondestimatenorm(n, cwork4, cwork1, anorm, kase, isave, rsave);
|
365
|
+
if( kase!=0 )
|
366
|
+
{
|
367
|
+
if( kase==kase1 )
|
368
|
+
{
|
369
|
+
|
370
|
+
//
|
371
|
+
// Multiply by U
|
372
|
+
//
|
373
|
+
for(i = 1; i <= n; i++)
|
374
|
+
{
|
375
|
+
v = 0.0;
|
376
|
+
for(i_=i; i_<=n;i_++)
|
377
|
+
{
|
378
|
+
v += lu(i,i_)*cwork1(i_);
|
379
|
+
}
|
380
|
+
cwork1(i) = v;
|
381
|
+
}
|
382
|
+
|
383
|
+
//
|
384
|
+
// Multiply by L
|
385
|
+
//
|
386
|
+
for(i = n; i >= 1; i--)
|
387
|
+
{
|
388
|
+
v = 0;
|
389
|
+
if( i>1 )
|
390
|
+
{
|
391
|
+
v = 0.0;
|
392
|
+
for(i_=1; i_<=i-1;i_++)
|
393
|
+
{
|
394
|
+
v += lu(i,i_)*cwork1(i_);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
cwork1(i) = v+cwork1(i);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
else
|
401
|
+
{
|
402
|
+
|
403
|
+
//
|
404
|
+
// Multiply by L'
|
405
|
+
//
|
406
|
+
for(i = 1; i <= n; i++)
|
407
|
+
{
|
408
|
+
cwork2(i) = 0;
|
409
|
+
}
|
410
|
+
for(i = 1; i <= n; i++)
|
411
|
+
{
|
412
|
+
v = cwork1(i);
|
413
|
+
if( i>1 )
|
414
|
+
{
|
415
|
+
for(i_=1; i_<=i-1;i_++)
|
416
|
+
{
|
417
|
+
cwork2(i_) = cwork2(i_) + v*ap::conj(lu(i,i_));
|
418
|
+
}
|
419
|
+
}
|
420
|
+
cwork2(i) = cwork2(i)+v;
|
421
|
+
}
|
422
|
+
|
423
|
+
//
|
424
|
+
// Multiply by U'
|
425
|
+
//
|
426
|
+
for(i = 1; i <= n; i++)
|
427
|
+
{
|
428
|
+
cwork1(i) = 0;
|
429
|
+
}
|
430
|
+
for(i = 1; i <= n; i++)
|
431
|
+
{
|
432
|
+
v = cwork2(i);
|
433
|
+
for(i_=i; i_<=n;i_++)
|
434
|
+
{
|
435
|
+
cwork1(i_) = cwork1(i_) + v*ap::conj(lu(i,i_));
|
436
|
+
}
|
437
|
+
}
|
438
|
+
}
|
439
|
+
}
|
440
|
+
}
|
441
|
+
while(kase!=0);
|
442
|
+
}
|
443
|
+
|
444
|
+
//
|
445
|
+
// Quick return if possible
|
446
|
+
//
|
447
|
+
if( anorm==0 )
|
448
|
+
{
|
449
|
+
return;
|
450
|
+
}
|
451
|
+
|
452
|
+
//
|
453
|
+
// Estimate the norm of inv(A).
|
454
|
+
//
|
455
|
+
ainvnm = 0;
|
456
|
+
if( onenorm )
|
457
|
+
{
|
458
|
+
kase1 = 1;
|
459
|
+
}
|
460
|
+
else
|
461
|
+
{
|
462
|
+
kase1 = 2;
|
463
|
+
}
|
464
|
+
kase = 0;
|
465
|
+
do
|
466
|
+
{
|
467
|
+
internalcomplexrcondestimatenorm(n, cwork4, cwork1, ainvnm, kase, isave, rsave);
|
468
|
+
if( kase!=0 )
|
469
|
+
{
|
470
|
+
if( kase==kase1 )
|
471
|
+
{
|
472
|
+
|
473
|
+
//
|
474
|
+
// Multiply by inv(L).
|
475
|
+
//
|
476
|
+
cw = complexsafesolvetriangular(lu, n, cwork1, false, 0, true, cwork2, cwork3);
|
477
|
+
if( !cw )
|
478
|
+
{
|
479
|
+
rcond = 0;
|
480
|
+
return;
|
481
|
+
}
|
482
|
+
|
483
|
+
//
|
484
|
+
// Multiply by inv(U).
|
485
|
+
//
|
486
|
+
cw = complexsafesolvetriangular(lu, n, cwork1, true, 0, false, cwork2, cwork3);
|
487
|
+
if( !cw )
|
488
|
+
{
|
489
|
+
rcond = 0;
|
490
|
+
return;
|
491
|
+
}
|
492
|
+
}
|
493
|
+
else
|
494
|
+
{
|
495
|
+
|
496
|
+
//
|
497
|
+
// Multiply by inv(U').
|
498
|
+
//
|
499
|
+
cw = complexsafesolvetriangular(lu, n, cwork1, true, 2, false, cwork2, cwork3);
|
500
|
+
if( !cw )
|
501
|
+
{
|
502
|
+
rcond = 0;
|
503
|
+
return;
|
504
|
+
}
|
505
|
+
|
506
|
+
//
|
507
|
+
// Multiply by inv(L').
|
508
|
+
//
|
509
|
+
cw = complexsafesolvetriangular(lu, n, cwork1, false, 2, true, cwork2, cwork3);
|
510
|
+
if( !cw )
|
511
|
+
{
|
512
|
+
rcond = 0;
|
513
|
+
return;
|
514
|
+
}
|
515
|
+
}
|
516
|
+
}
|
517
|
+
}
|
518
|
+
while(kase!=0);
|
519
|
+
|
520
|
+
//
|
521
|
+
// Compute the estimate of the reciprocal condition number.
|
522
|
+
//
|
523
|
+
if( ainvnm!=0 )
|
524
|
+
{
|
525
|
+
rcond = 1/ainvnm;
|
526
|
+
rcond = rcond/anorm;
|
527
|
+
}
|
528
|
+
}
|
529
|
+
|
530
|
+
|
531
|
+
static void internalcomplexrcondestimatenorm(const int& n,
|
532
|
+
ap::complex_1d_array& v,
|
533
|
+
ap::complex_1d_array& x,
|
534
|
+
double& est,
|
535
|
+
int& kase,
|
536
|
+
ap::integer_1d_array& isave,
|
537
|
+
ap::real_1d_array& rsave)
|
538
|
+
{
|
539
|
+
int itmax;
|
540
|
+
int i;
|
541
|
+
int iter;
|
542
|
+
int j;
|
543
|
+
int jlast;
|
544
|
+
int jump;
|
545
|
+
double absxi;
|
546
|
+
double altsgn;
|
547
|
+
double estold;
|
548
|
+
double safmin;
|
549
|
+
double temp;
|
550
|
+
int i_;
|
551
|
+
|
552
|
+
|
553
|
+
//
|
554
|
+
//Executable Statements ..
|
555
|
+
//
|
556
|
+
itmax = 5;
|
557
|
+
safmin = ap::minrealnumber;
|
558
|
+
if( kase==0 )
|
559
|
+
{
|
560
|
+
for(i = 1; i <= n; i++)
|
561
|
+
{
|
562
|
+
x(i) = double(1)/double(n);
|
563
|
+
}
|
564
|
+
kase = 1;
|
565
|
+
jump = 1;
|
566
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
567
|
+
return;
|
568
|
+
}
|
569
|
+
internalcomplexrcondloadall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
570
|
+
|
571
|
+
//
|
572
|
+
// ENTRY (JUMP = 1)
|
573
|
+
// FIRST ITERATION. X HAS BEEN OVERWRITTEN BY A*X.
|
574
|
+
//
|
575
|
+
if( jump==1 )
|
576
|
+
{
|
577
|
+
if( n==1 )
|
578
|
+
{
|
579
|
+
v(1) = x(1);
|
580
|
+
est = ap::abscomplex(v(1));
|
581
|
+
kase = 0;
|
582
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
583
|
+
return;
|
584
|
+
}
|
585
|
+
est = internalcomplexrcondscsum1(x, n);
|
586
|
+
for(i = 1; i <= n; i++)
|
587
|
+
{
|
588
|
+
absxi = ap::abscomplex(x(i));
|
589
|
+
if( absxi>safmin )
|
590
|
+
{
|
591
|
+
x(i) = x(i)/absxi;
|
592
|
+
}
|
593
|
+
else
|
594
|
+
{
|
595
|
+
x(i) = 1;
|
596
|
+
}
|
597
|
+
}
|
598
|
+
kase = 2;
|
599
|
+
jump = 2;
|
600
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
601
|
+
return;
|
602
|
+
}
|
603
|
+
|
604
|
+
//
|
605
|
+
// ENTRY (JUMP = 2)
|
606
|
+
// FIRST ITERATION. X HAS BEEN OVERWRITTEN BY CTRANS(A)*X.
|
607
|
+
//
|
608
|
+
if( jump==2 )
|
609
|
+
{
|
610
|
+
j = internalcomplexrcondicmax1(x, n);
|
611
|
+
iter = 2;
|
612
|
+
|
613
|
+
//
|
614
|
+
// MAIN LOOP - ITERATIONS 2,3,...,ITMAX.
|
615
|
+
//
|
616
|
+
for(i = 1; i <= n; i++)
|
617
|
+
{
|
618
|
+
x(i) = 0;
|
619
|
+
}
|
620
|
+
x(j) = 1;
|
621
|
+
kase = 1;
|
622
|
+
jump = 3;
|
623
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
624
|
+
return;
|
625
|
+
}
|
626
|
+
|
627
|
+
//
|
628
|
+
// ENTRY (JUMP = 3)
|
629
|
+
// X HAS BEEN OVERWRITTEN BY A*X.
|
630
|
+
//
|
631
|
+
if( jump==3 )
|
632
|
+
{
|
633
|
+
for(i_=1; i_<=n;i_++)
|
634
|
+
{
|
635
|
+
v(i_) = x(i_);
|
636
|
+
}
|
637
|
+
estold = est;
|
638
|
+
est = internalcomplexrcondscsum1(v, n);
|
639
|
+
|
640
|
+
//
|
641
|
+
// TEST FOR CYCLING.
|
642
|
+
//
|
643
|
+
if( est<=estold )
|
644
|
+
{
|
645
|
+
|
646
|
+
//
|
647
|
+
// ITERATION COMPLETE. FINAL STAGE.
|
648
|
+
//
|
649
|
+
altsgn = 1;
|
650
|
+
for(i = 1; i <= n; i++)
|
651
|
+
{
|
652
|
+
x(i) = altsgn*(1+double(i-1)/double(n-1));
|
653
|
+
altsgn = -altsgn;
|
654
|
+
}
|
655
|
+
kase = 1;
|
656
|
+
jump = 5;
|
657
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
658
|
+
return;
|
659
|
+
}
|
660
|
+
for(i = 1; i <= n; i++)
|
661
|
+
{
|
662
|
+
absxi = ap::abscomplex(x(i));
|
663
|
+
if( absxi>safmin )
|
664
|
+
{
|
665
|
+
x(i) = x(i)/absxi;
|
666
|
+
}
|
667
|
+
else
|
668
|
+
{
|
669
|
+
x(i) = 1;
|
670
|
+
}
|
671
|
+
}
|
672
|
+
kase = 2;
|
673
|
+
jump = 4;
|
674
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
675
|
+
return;
|
676
|
+
}
|
677
|
+
|
678
|
+
//
|
679
|
+
// ENTRY (JUMP = 4)
|
680
|
+
// X HAS BEEN OVERWRITTEN BY CTRANS(A)*X.
|
681
|
+
//
|
682
|
+
if( jump==4 )
|
683
|
+
{
|
684
|
+
jlast = j;
|
685
|
+
j = internalcomplexrcondicmax1(x, n);
|
686
|
+
if( ap::abscomplex(x(jlast))!=ap::abscomplex(x(j))&&iter<itmax )
|
687
|
+
{
|
688
|
+
iter = iter+1;
|
689
|
+
|
690
|
+
//
|
691
|
+
// MAIN LOOP - ITERATIONS 2,3,...,ITMAX.
|
692
|
+
//
|
693
|
+
for(i = 1; i <= n; i++)
|
694
|
+
{
|
695
|
+
x(i) = 0;
|
696
|
+
}
|
697
|
+
x(j) = 1;
|
698
|
+
kase = 1;
|
699
|
+
jump = 3;
|
700
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
701
|
+
return;
|
702
|
+
}
|
703
|
+
|
704
|
+
//
|
705
|
+
// ITERATION COMPLETE. FINAL STAGE.
|
706
|
+
//
|
707
|
+
altsgn = 1;
|
708
|
+
for(i = 1; i <= n; i++)
|
709
|
+
{
|
710
|
+
x(i) = altsgn*(1+double(i-1)/double(n-1));
|
711
|
+
altsgn = -altsgn;
|
712
|
+
}
|
713
|
+
kase = 1;
|
714
|
+
jump = 5;
|
715
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
716
|
+
return;
|
717
|
+
}
|
718
|
+
|
719
|
+
//
|
720
|
+
// ENTRY (JUMP = 5)
|
721
|
+
// X HAS BEEN OVERWRITTEN BY A*X.
|
722
|
+
//
|
723
|
+
if( jump==5 )
|
724
|
+
{
|
725
|
+
temp = 2*(internalcomplexrcondscsum1(x, n)/(3*n));
|
726
|
+
if( temp>est )
|
727
|
+
{
|
728
|
+
for(i_=1; i_<=n;i_++)
|
729
|
+
{
|
730
|
+
v(i_) = x(i_);
|
731
|
+
}
|
732
|
+
est = temp;
|
733
|
+
}
|
734
|
+
kase = 0;
|
735
|
+
internalcomplexrcondsaveall(isave, rsave, i, iter, j, jlast, jump, absxi, altsgn, estold, temp);
|
736
|
+
return;
|
737
|
+
}
|
738
|
+
}
|
739
|
+
|
740
|
+
|
741
|
+
static double internalcomplexrcondscsum1(const ap::complex_1d_array& x,
|
742
|
+
int n)
|
743
|
+
{
|
744
|
+
double result;
|
745
|
+
int i;
|
746
|
+
|
747
|
+
result = 0;
|
748
|
+
for(i = 1; i <= n; i++)
|
749
|
+
{
|
750
|
+
result = result+ap::abscomplex(x(i));
|
751
|
+
}
|
752
|
+
return result;
|
753
|
+
}
|
754
|
+
|
755
|
+
|
756
|
+
static int internalcomplexrcondicmax1(const ap::complex_1d_array& x, int n)
|
757
|
+
{
|
758
|
+
int result;
|
759
|
+
int i;
|
760
|
+
double m;
|
761
|
+
|
762
|
+
result = 1;
|
763
|
+
m = ap::abscomplex(x(1));
|
764
|
+
for(i = 2; i <= n; i++)
|
765
|
+
{
|
766
|
+
if( ap::abscomplex(x(i))>m )
|
767
|
+
{
|
768
|
+
result = i;
|
769
|
+
m = ap::abscomplex(x(i));
|
770
|
+
}
|
771
|
+
}
|
772
|
+
return result;
|
773
|
+
}
|
774
|
+
|
775
|
+
|
776
|
+
static void internalcomplexrcondsaveall(ap::integer_1d_array& isave,
|
777
|
+
ap::real_1d_array& rsave,
|
778
|
+
int& i,
|
779
|
+
int& iter,
|
780
|
+
int& j,
|
781
|
+
int& jlast,
|
782
|
+
int& jump,
|
783
|
+
double& absxi,
|
784
|
+
double& altsgn,
|
785
|
+
double& estold,
|
786
|
+
double& temp)
|
787
|
+
{
|
788
|
+
|
789
|
+
isave(0) = i;
|
790
|
+
isave(1) = iter;
|
791
|
+
isave(2) = j;
|
792
|
+
isave(3) = jlast;
|
793
|
+
isave(4) = jump;
|
794
|
+
rsave(0) = absxi;
|
795
|
+
rsave(1) = altsgn;
|
796
|
+
rsave(2) = estold;
|
797
|
+
rsave(3) = temp;
|
798
|
+
}
|
799
|
+
|
800
|
+
|
801
|
+
static void internalcomplexrcondloadall(ap::integer_1d_array& isave,
|
802
|
+
ap::real_1d_array& rsave,
|
803
|
+
int& i,
|
804
|
+
int& iter,
|
805
|
+
int& j,
|
806
|
+
int& jlast,
|
807
|
+
int& jump,
|
808
|
+
double& absxi,
|
809
|
+
double& altsgn,
|
810
|
+
double& estold,
|
811
|
+
double& temp)
|
812
|
+
{
|
813
|
+
|
814
|
+
i = isave(0);
|
815
|
+
iter = isave(1);
|
816
|
+
j = isave(2);
|
817
|
+
jlast = isave(3);
|
818
|
+
jump = isave(4);
|
819
|
+
absxi = rsave(0);
|
820
|
+
altsgn = rsave(1);
|
821
|
+
estold = rsave(2);
|
822
|
+
temp = rsave(3);
|
823
|
+
}
|
824
|
+
|
825
|
+
|
826
|
+
|