#include < tnt.h >
#include < jama_svd.h >
void svbksb(TNT::Array2D&u, TNT::Array1D &w, TNT::Array2D &v, int m, int n, TNT::Array1D &b, TNT::Array1D &x)
{
int jj,j,i;
float s;
TNT::Array1D< float > tmp(n, 0.0f);
for (j=0; j < n; j++) {
s = 0.0;
if ( w[j]) {
for (i = 0; i < m; i++) s += u[i][j]*b[i];
s /= w[j];
}
tmp[j]=s;
}
for (j=0;j < n;j++) {
s=0.0;
for (jj=0;jj < n;jj++) s += v[j][jj]*tmp[jj];
x[j]=s;
}
}
void svd_solve(TNT::Array2DA, TNT::Array1D b, TNT::Array1D &sol){
int m=A.dim1();
int n=A.dim2();
JAMA::SVDsvd(A);
TNT::Array2Du;
svd.getU(u);
TNT::Array1Dw;
svd.getSingularValues(w);
TNT::Array2Dv;
svd.getV(v);
svbksb(u, w, v, m, n, b, sol);
}
int main(int argc, char* argv[]){
int n, m;
n=m=8;
TNT::Array2DA(m, n, 0.0);
TNT::Array1Db(m, 0.0);
TNT::Array1Dsol(n, 0.0);
//here fill in A and b
svd_solve(A, b, sol){
}
Monday, September 3, 2007
[Work] SVD example
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment