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

📄 d11r5.cpp

📁 Visual C++ 常用数值算法集 源代码
💻 CPP
字号:
#include "iostream.h"
#include "math.h"

double famoeb(double x[])
{
	double aaa;
    aaa = (x[1] - 0.5) * (x[1] - 0.5) + (x[2] - 0.6) * 
		  (x[2] - 0.6) + (x[3] - 0.7) * (x[3] - 0.7);
    return 0.6 - bessj0(aaa);
}

void main()
{
    //program d11r5
    //driver for routine amoeba
    int iter,ndim,np = 3;
    int i,j,mp = 4;
    double ftol = 0.000001;
    double p[13], x[4], y[5];
    p[1] = 0.0;  p[2] = 0.0;  p[3] = 0.0;
    p[4] = 1.0;  p[5] = 0.0;  p[6] = 0.0;
    p[7] = 0.0;  p[8] = 1.0;  p[9] = 0.0;
    p[10] = 0.0; p[11] = 0.0; p[12] = 1.0;
    ndim = np;
    for (i = 1; i<=mp; i++)
	{
        for (j = 1; j<=np; j++)
		{
            x[j] = p[(i-1)*np+j];
        }
        y[i] = famoeb(x);
    }
    amoeba(p, y, mp, np, ndim, ftol, iter);
    cout<<endl;
    cout<<"Iterations: "<<iter<<endl;
    cout<<"Vertices of final 3-D simplex and"<<endl;
    cout<<"function values at the vertices:"<<endl;
    cout<<"i     x(i)      y(i)    z(i)     function"<<endl;
	cout.setf(ios::fixed|ios::left);
	cout.precision(6);
    for (i = 1; i<=mp; i++)
	{
		cout.width(6);
        cout<<i;
        for (j = 1; j<=np; j++)
		{
			cout.width(12);
			cout<<p[(i-1)*np+j];
        }
		cout.width(12);
        cout<<y[i]<<endl;
    }
	cout<<endl;
    cout<<"True minimum is at ( 0.5, 0.6, 0.7)"<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -