?? d11r8.cpp
字號:
#include "iostream.h"
#include "math.h"
#include "stdlib.h"
double func2(double x[], int n)
{
return 1.0 - bessj0(x[1] - 0.5) * bessj0(x[2] - 0.5)
* bessj0(x[3] - 0.5);
}
double func(double x)
{
return f1dim(x);
}
void dfunc(double x[], double df[])
{
df[1]=bessj1(x[1]-0.5)*bessj0(x[2]-0.5)*bessj0(x[3]-0.5);
df[2]=bessj0(x[1]-0.5)*bessj1(x[2]-0.5)*bessj0(x[3]-0.5);
df[3]=bessj0(x[1]-0.5)*bessj0(x[2]-0.5)*bessj1(x[3]-0.5);
}
void main()
{
//program d11r8
//driver for routine frprmn
int iter,k,ndim = 3;
double fret,angl,pio2 = 1.5707963;
double ftol = 0.000001;
double p[4];
cout<<"Program finds the minimum of a function"<<endl;
cout<<"with different trial starting vectors."<<endl;
cout<<"True minimum is (0.5, 0.5, 0.5)"<<endl;
cout.setf(ios::fixed|ios::left);
cout.precision(6);
for (k = 0; k<=4; k++)
{
angl = pio2 * k / 4.0;
p[1] = 2.0 * cos(angl);
p[2] = 2.0 * sin(angl);
p[3] = 0.0;
cout<<endl;
cout<<"Starting vector: (";
cout.width(12);
cout<<p[1];
cout.width(12);
cout<<p[2];
cout.width(7);
cout<<p[3]<<")"<<endl;
frprmn(p, ndim, ftol, iter, fret);
cout<<"Iterations: "<<iter<<endl;
cout<<"Solution vector: (";
cout.width(12);
cout<<p[1];
cout.width(12);
cout<<p[2];
cout.width(7);
cout<<p[3]<<")"<<endl;
cout.setf(ios::scientific);
cout<<"func. value at solution "<<fret<<endl;
cout.unsetf(ios::scientific);
cout.setf(ios::fixed);
cout.precision(6);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -