?? d11r6.cpp
字號:
#include "iostream.h"
#include "math.h"
double func2(double x[], int n)
{
return 0.5 - bessj0(pow((x[1] - 1.0) , 2) +
pow((x[2] - 2.0), 2) + pow((x[3] - 3.0) , 2));
}
double func(double x)
{
return f1dim(x);
}
void main()
{
//program d11r6
//driver for routine powell
int i,j,iter,ndim,np = 3;
ndim = np;
double fret,ftol = 0.000001;
double p[4], xi[10];
for (i = 1; i<=np; i++)
{
for (j = 1; j<=np; j++)
{
xi[(i-1)*np+j] = 0.0;
}
}
xi[1] = 1.0;
xi[1*np+2] = 1.0;
xi[2*np+3] = 1.0;
p[1] = 1.5; p[2] = 1.5; p[3] = 2.5;
powell(p, xi, ndim, np, ftol, iter, fret);
cout<<endl;
cout<<"Iterations: "<<iter<<endl;
cout<<"minimum found at: "<<endl;
cout.setf(ios::fixed|ios::left);
cout.precision(6);
for (i = 1; i<=np; i++)
{
cout.width(12);
cout<<p[i];
}
cout<<endl;
cout<<"minimum function value = "<<fret;
cout<<endl;
cout<<"True minimum of function is at: 1.0 2.0 3.0"<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -