xdf1dim.cpp
来自「这是C++数值算法(第二版)的源代码,其中包含了目前一些比较常用的数值计算的算法」· C++ 代码 · 共 40 行
CPP
40 行
#include <iostream>
#include <iomanip>
#include "nr.h"
using namespace std;
// Driver for routine df1dim
int ncom; // defining declarations
DP (*nrfunc)(Vec_I_DP &);
Vec_DP *pcom_p,*xicom_p;
void (*nrdfun)(Vec_I_DP &, Vec_O_DP &);
void dfunc(Vec_I_DP &x, Vec_O_DP &df)
{
int i;
for (i=0;i<3;i++)
df[i]=(x[i]-1.0)*(x[i]-1.0);
}
int main(void)
{
const int NDIM=3;
ncom=NDIM;
pcom_p=new Vec_DP(ncom);
xicom_p=new Vec_DP(ncom);
Vec_DP &pcom=*pcom_p, &xicom=*xicom_p;
nrdfun=dfunc;
cout << endl << "Enter vector direction along which to" << endl;
cout << "plot the function. Minimum is in the" << endl;
cout << "direction 1.0 1.0 1.0 - enter x y z:" << endl << endl;
pcom[0]=pcom[1]=pcom[2]=0.0;
cin >> xicom[0] >> xicom[1] >> xicom[2];
NR::scrsho(NR::df1dim);
delete xicom_p;
delete pcom_p;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?