问题描述
- 哪位知道下面这个函数的功能啊!谢谢
- int HOUS(double c[][MMax] double d[] double x[] double eps double &rd int m int n)
{
/*
c: c[1..n][1..m]
d: d[1..n]
m: the number of unknown
n: the number of equations
rd: ||d+cx||
*/
double lk ckk beta sm;
double qk[MMax] ad[MMax];
int ijk;for(k=1; k<=m; k++){
for(sm=0 i=k; i<=n; i++) sm+=c[i][k]*c[i][k]; //ak^2=sigma(cik*cik) for i=k to nif(sm < eps) return -1; //error occursckk=c[k][k];lk=ckk<0? sqrt(sm) : -sqrt(sm); //lk = -sign(ckk)*sqrt(sm) //L={0 ... lk 0 ... 0} //S={0... ckk ck+1k ... cnk}ad[k]=lk; //sigma=||S-L||^2=(ckk-lk)^2 + S*S - ckk^2 // =S*S + (2ckk-lk)(-lk) // =lk^2 - 2ckk*lk +lk^2 // =2lk^2-2ckk*lk // =2sm-2ckk*lkbeta=1/(sm-ckk*lk); //2 / sigma =1/(sm-ckk*lk)c[k][k]=ckk-lk; //U=S-Lif(k<m) for(j=k+1; j<=m; j++){ for(sm=0 i=k; i<=n; i++) sm+=c[i][k]*c[i][j]; //U*cj qk[j]=beta*sm; //Qkj=2U*cj/sigma for(i=k; i<=n; i++) c[i][j]-=c[i][k]*qk[j]; }for(sm=0 i=k; i<=n; i++) sm+=c[i][k]*d[i];sm*=beta;for(i=k; i<=n; i++) d[i]-=c[i][k]*sm;
}// tri-anglized
for(i=m; i>=1; i--){
d[i]/=ad[i];
x[i]=d[i];
if(i>1)
for(j=1; j<i; j++)
d[j]-=c[j][i]*d[i];
}for(rd=0 i=m+1; i<=n; i++)
rd+=d[i]*d[i]; // remained error
return 0;
}
时间: 2024-11-01 13:22:15