⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cholesky.h

📁 本系统采用VC开发.可实现点云数据的处理,图像缩放,生成曲面.
💻 H
字号:
// Template Numerical Toolkit (TNT) for Linear Algebra//// BETA VERSION INCOMPLETE AND SUBJECT TO CHANGE// Please see http://math.nist.gov/tnt for updates//// R. Pozo// Mathematical and Computational Sciences Division// National Institute of Standards and Technology#ifndef CHOLESKY_H#define CHOLESKY_H#include <math.h>// NOTE: this code uses sqrt(), may need to link with -lm// index method#if 1// scalar point method////// Only upper part of A is used.  Cholesky factor is returned in// lower part of L.//template <class SPDMatrix, class SymmMatrix>int Cholesky_upper_factorization(SPDMatrix &A, SymmMatrix &L){    Subscript M = A.dim(1);    Subscript N = A.dim(2);    assert(M == N);                 // make sure A is square    // readjust size of L, if necessary    if (M != L.dim(1) || N != L.dim(2))        L = SymmMatrix(N,N);    Subscript i,j,k;    typename SPDMatrix::element_type dot=0;    for (j=1; j<=N; j++)                // form column j of L    {        dot= 0;        for (i=1; i<j; i++)             // for k= 1 TO j-1            dot = dot +  L(j,i)*L(j,i);        L(j,j) = A(j,j) - dot;        for (i=j+1; i<=N; i++)        {            dot = 0;            for (k=1; k<j; k++)                dot = dot +  L(i,k)*L(j,k);            L(i,j) = A(j,i) - dot;        }        if (L(j,j) <= 0.0) return 1;        L(j,j) = sqrt( L(j,j) );        for (i=j+1; i<=N; i++)            L(i,j) = L(i,j) / L(j,j);    }    return 0;}#else       /* use vector/matrix index regions */template <class Matrix, class Vector>void Cholesky_lower_factorization(Matrix &A, Vector &b){    Subscript m = A.dim(1);    Subscript n = A.dim(2);    Subscript i,j;    Subscript N = (m < n ? n : m);          // K = min(M,N);    assert( N <= b.dim() );    for (j=1; j<=N; j++)    {        Index J(1, j-1);        L(j,j) = A(j,j) - dot_product(L(j,J), L(j,J));        for (i=j+1; j<=N; j++)            L(i,j) = A(j,i) - dot_product( L(i,J), L(j,J));        L(j,j) = sqrt( L(j,j) );        for (i=j+1; j<=N; j++)            L(i,j) = L(i,j) / L(j,j);    }}#endif// TNT_USE_REGIONS#endif// CHOLESKY_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -