⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d11r6.cpp

📁 Visual C++ 常用数值算法集 源代码
💻 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 + -