#ifndef JAMA_EIG_H
#define JAMA_EIG_H
#include "tnt_array1d.h"
#include "tnt_array2d.h"
#include "tnt_math_utils.h"
#include <algorithm>
// for min(), max() below
#include <cmath>
// for abs() below
using namespace TNT;
using namespace std;
namespace JAMA
{
/**
Computes eigenvalues and eigenvectors of a real (non-complex)
matrix.
<P>
If A is symmetric, then A = V*D*V' where the eigenvalue matrix D is
diagonal and the eigenvector matrix V is orthogonal. That is,
the diagonal values of D are the eigenvalues, and
V*V' = I, where I is the identity matrix. The columns of V
represent the eigenvectors in the sense that A*V = V*D.
<P>
If A is not symmetric, then the eigenvalue matrix D is block diagonal
with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues,
a + i*b, in 2-by-2 blocks, [a, b; -b, a]. That is, if the complex
eigenvalues look like
<pre>
u + iv . . . . .
. u - iv . . . .
. . a + ib . . .
. . . a - ib . .
. . . . x .
. . . . . y
</pre>
then D looks like
<pre>
u v . . . .
-v u . . . .
. . a b . .
. . -b a . .
. . . . x .
. . . . . y
</pre>
This keeps V a real matrix in both symmetric and non-symmetric
cases, and A*V = V*D.
<p>
The matrix V may be badly
conditioned, or even singular, so the validity of the equation
A = V*D*inverse(V) depends upon the condition number of V.
<p>
(Adapted from JAMA, a Java Matrix Library, developed by jointly
by the Mathworks and NIST; see http://math.nist.gov/javanumerics/jama).
**/
template <class Real>
class Eigenvalue
{
/** Row and column dimension (square matrix). */
int n;
int issymmetric; /* boolean*/
/** Arrays for internal storage of eigenvalues. */
TNT::Array1D<Real> d; /* real part */
TNT::Array1D<Real> e; /* img part */
/** Array for internal storage of eigenvectors. */
TNT::Array2D<Real> V;
/** Array for internal storage of nonsymmetric Hessenberg form.
@serial internal storage of nonsymmetric Hessenberg form.
*/
TNT::Array2D<Real> H;
/** Working storage for nonsymmetric algorithm.
@serial working storage for nonsymmetric algorithm.
*/
TNT::Array1D<Real> ort;
// Symmetric Householder reduction to tridiagonal form.
void tred2() {
// This is derived from the Algol procedures tred2 by
// Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
// Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
// Fortran subroutine in EISPACK.
for (int j = 0; j < n; j++) {
d[j] = V[n-1][j];
}
// Householder reduction to tridiagonal form.
for (int i = n-1; i > 0; i--) {
// Scale to avoid under/overflow.
Real scale = 0.0;
Real h = 0.0;
for (int k = 0; k < i; k++) {
scale = scale + abs(d[k]);
}
if (scale == 0.0) {
e[i] = d[i-1];
for (int j = 0; j < i; j++) {
d[j] = V[i-1][j];
V[i][j] = 0.0;
V[j][i] = 0.0;
}
} else {
// Generate Householder vector.
for (int k = 0; k < i; k++) {
d[k] /= scale;
h += d[k] * d[k];
}
Real f = d[i-1];
Real g = sqrt(h);
if (f > 0) {
g = -g;
}
e[i] = scale * g;
h = h - f * g;
d[i-1] = f - g;
for (int j = 0; j < i; j++) {
e[j] = 0.0;
}
// Apply similarity transformation to remaining columns.
for (int j = 0; j < i; j++) {
f = d[j];
V[j][i] = f;
g = e[j] + V[j][j] * f;
for (int k = j+1; k <= i-1; k++) {
g += V[k][j] * d[k];
e[k] += V[k][j] * f;
}
e[j] = g;
}
f = 0.0;
for (int j = 0; j < i; j++) {
e[j] /= h;
f += e[j] * d[j];
}
Real hh = f / (h + h);
for (int j = 0; j < i; j++) {
e[j] -= hh * d[j];
}
for (int j = 0; j < i; j++) {
f = d[j];
g = e[j];
for (int k = j; k <= i-1; k++) {
V[k][j] -= (f * e[k] + g * d[k]);
}
d[j] = V[i-1][j];
V[i][j] = 0.0;
}
}
d[i] = h;
}
// Accumulate transformations.
for (int i = 0; i < n-1; i++) {
V[n-1][i] = V[i][i];
V[i][i] = 1.0;
Real h = d[i+1];
if (h != 0.0) {
for (int k = 0; k <= i; k++) {
d[k] = V[k][i+1] / h;
}
for (int j = 0; j <= i; j++) {
Real g = 0.0;
for (int k = 0; k <= i; k++) {
g += V[k][i+1] * V[k][j];
}
for (int k = 0; k <= i; k++) {
V[k][j] -= g * d[k];
}
}
}
for (int k = 0; k <= i; k++) {
V[k][i+1] = 0.0;
}
}
for (int j = 0; j < n; j++) {
d[j] = V[n-1][j];
V[n-1][j] = 0.0;
}
V[n-1][n-1] = 1.0;
e[0] = 0.0;
}
// Symmetric tridiagonal QL algorithm.
void tql2 () {
// This is derived from the Algol procedures tql2, by
// Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
// Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
// Fortran subroutine in EISPACK.
for (int i = 1; i < n; i++) {
e[i-1] = e[i];
}
e[n-1] = 0.0;
Real f = 0.0;
Real tst1 = 0.0;
Real eps = pow(2.0,-52.0);
for (int l = 0; l < n; l++) {
// Find small subdiagonal element
tst1 = max(tst1,abs(d[l]) + abs(e[l]));
int m = l;
// Original while-loop from Java code
while (m < n) {
if (abs(e[m]) <= eps*tst1) {
break;
}
m++;
}
// If m == l, d[l] is an eigenvalue,
// otherwise, iterate.
if (m > l) {
int iter = 0;
do {
iter = iter + 1; // (Could check iteration count here.)
// Compute implicit shift
Real g = d[l];
Real p = (d[l+1] - g) / (2.0 * e[l]);
Real r = hypot(p,1.0);
if (p < 0) {
r = -r;
}
d[l] = e[l] / (p + r);
d[l+1] = e[l] * (p + r);
Real dl1 = d[l+1];
Real h = g - d[l];
for (int i = l+2; i < n; i++) {
d[i] -= h;
}
f = f + h;
// Implicit QL transformation.
p = d[m];
Real c = 1.0;
Real c2 = c;
Real c3 = c;
Real el1 = e[l+1];
Real s = 0.0;
Real s2 = 0.0;
for (int i = m-1; i >= l; i--) {
c3 = c2;
c2 = c;
s2 = s;
g = c * e[i];
h = c * p;
r = hypot(p,e[i]);
e[i+1] = s * r;
s = e[i] / r;
c = p / r;
没有合适的资源?快使用搜索试试~ 我知道了~
TNT.rar_tnt
共125个文件
html:95个
h:26个
gif:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 191 浏览量
2022-09-22
19:00:08
上传
评论
收藏 201KB RAR 举报
温馨提示
标准模板程序包,包括向量与矩阵的基本算法实现。
资源推荐
资源详情
资源评论
收起资源包目录
TNT.rar_tnt (125个子文件)
doxygen.css 885B
doxygen.css 885B
doxygen.gif 2KB
doxygen.gif 2KB
jama_eig.h 28KB
jama_svd.h 14KB
tnt_cmat.h 11KB
jama_qr.h 7KB
tnt_vec.h 7KB
jama_lu.h 7KB
tnt_fortran_array1d.h 5KB
jama_cholesky.h 5KB
tnt_array3d.h 5KB
tnt_array2d.h 5KB
tnt_array1d.h 5KB
tnt_fortran_array3d_utils.h 5KB
tnt_array2d_utils.h 5KB
tnt_fortran_array3d.h 4KB
tnt_i_refvec.h 4KB
tnt_fortran_array2d.h 4KB
tnt_fortran_array2d_utils.h 4KB
tnt_fortran_array1d_utils.h 4KB
tnt_array3d_utils.h 4KB
tnt_array1d_utils.h 3KB
tnt_sparse_matrix_csr.h 3KB
tnt.h 2KB
tnt_stopwatch.h 2KB
tnt_subscript.h 2KB
tnt_version.h 1KB
tnt_math_utils.h 494B
namespace_TNT.html 101KB
jama_eig_h-source.html 43KB
class_TNT__Matrix.html 36KB
jama_svd_h-source.html 26KB
class_TNT__Fortran_Array3D.html 25KB
class_TNT__Array2D.html 24KB
class_TNT__Array1D.html 23KB
class_TNT__Fortran_Array2D.html 23KB
class_TNT__Array3D.html 22KB
class_TNT__Fortran_Array1D.html 22KB
class_TNT__Vector.html 15KB
jama_lu_h-source.html 14KB
class_JAMA__Cholesky.html 13KB
jama_qr_h-source.html 13KB
tnt_cmat_h-source.html 13KB
functions.html 12KB
class_TNT__Sparse_Matrix_CompRow.html 12KB
class_JAMA__LU.html 11KB
class_JAMA__QR.html 11KB
jama_cholesky_h-source.html 11KB
tnt_fortran_array3d_h-source.html 11KB
class_JAMA__Eigenvalue.html 10KB
tnt_fortran_array2d_h-source.html 10KB
tnt_vec_h-source.html 9KB
class_JAMA__SVD.html 9KB
tnt_array3d_h-source.html 9KB
tnt_fortran_array1d_h-source.html 9KB
tnt_array1d_h-source.html 7KB
tnt_array2d_h-source.html 7KB
class_TNT__Stopwatch.html 7KB
tnt_array2d_utils_h-source.html 6KB
tnt_sparse_matrix_csr_h-source.html 6KB
tnt_fortran_array1d_utils_h-source.html 6KB
tnt_fortran_array3d_utils_h-source.html 5KB
tnt_array1d_utils_h-source.html 5KB
jama_cholesky_old_h-source.html 5KB
tnt_version_h.html 5KB
tnt_fortran_array2d_utils_h-source.html 5KB
tnt_subscript_h-source.html 5KB
class_TNT__Matrix-members.html 5KB
tnt_stopwatch_h-source.html 4KB
tnt_array3d_utils_h-source.html 4KB
tnt_version_h-source.html 4KB
tnt_math_utils_h-source.html 4KB
files.html 4KB
functions.html 3KB
class_TNT__Fortran_Array3D-members.html 3KB
namespacemembers.html 3KB
class_TNT__Fortran_Array2D-members.html 3KB
class_TNT__Fortran_Array1D-members.html 3KB
class_TNT__Array2D-members.html 3KB
class_TNT__Array1D-members.html 3KB
tnt_subscript_h.html 3KB
class_TNT__Array3D-members.html 3KB
class_TNT__Vector-members.html 3KB
class_TNT__Sparse_Matrix_CompRow-members.html 2KB
annotated.html 2KB
class_JAMA__Cholesky-members.html 2KB
class_JAMA__SVD-members.html 2KB
class_JAMA__LU-members.html 2KB
class_JAMA__QR-members.html 2KB
globals.html 2KB
tnt_cmat_h.html 2KB
namespace_JAMA.html 2KB
class_TNT__Stopwatch-members.html 2KB
class_JAMA__Eigenvalue-members.html 2KB
tnt_vec_h.html 2KB
tnt_fortran_array1d_h.html 2KB
tnt_fortran_array3d_h.html 2KB
tnt_fortran_array2d_h.html 2KB
共 125 条
- 1
- 2
资源评论
邓凌佳
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_2024-05-21-17-06-42-64_2332cb9b27b851b548ba47a91682926c.jpg
- 毕业设计参考 - 基于树莓派、OpenCV及Python的人脸识别
- node-v18.20.2-linux-arm64
- 222222222222
- 16张相机标定图片,可复现本文畸变矫正
- dbeaver-ce-23.3.1-x86_64-setup.zip
- 基于X86 AVX2指令的快速卷积实现
- VMware-ESXi-7.0U3n-21930508-depot.zip文件
- MySQL 在 Windows 系统下的安装教程.zip
- Access文件数据库访问的客户端
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功