?? frprmn.cpp
字號:
#include <cmath>
#include "nr.h"
using namespace std;
void NR::frprmn(Vec_IO_DP &p, const DP ftol, int &iter, DP &fret,
DP func(Vec_I_DP &), void dfunc(Vec_I_DP &, Vec_O_DP &))
{
const int ITMAX=200;
const DP EPS=1.0e-18;
int j,its;
DP gg,gam,fp,dgg;
int n=p.size();
Vec_DP g(n),h(n),xi(n);
fp=func(p);
dfunc(p,xi);
for (j=0;j<n;j++) {
g[j] = -xi[j];
xi[j]=h[j]=g[j];
}
for (its=0;its<ITMAX;its++) {
iter=its;
linmin(p,xi,fret,func);
if (2.0*fabs(fret-fp) <= ftol*(fabs(fret)+fabs(fp)+EPS))
return;
fp=fret;
dfunc(p,xi);
dgg=gg=0.0;
for (j=0;j<n;j++) {
gg += g[j]*g[j];
// dgg += xi[j]*xi[j];
dgg += (xi[j]+g[j])*xi[j];
}
if (gg == 0.0)
return;
gam=dgg/gg;
for (j=0;j<n;j++) {
g[j] = -xi[j];
xi[j]=h[j]=g[j]+gam*h[j];
}
}
nrerror("Too many iterations in frprmn");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -