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

📄 d11r8.cpp

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