d10r7.cpp

来自「工程算法 这是一个很有用的工程数值算法集锦」· C++ 代码 · 共 38 行

CPP
38
字号
#include <process.h>
#include <math.h>
#include <iomanip.h>
#include <iostream.h>

double func(double x)
{
	double t;
	t=bessj0( x);
	return t;
}

void main()
{
    //program d10r7
    //driver for routine zbrent
	int n,nbmax,nb,i;
	double  x1,x2,tol,root,xb1[21],xb2[21];
    n = 100;
    nbmax = 20;
    x1 = 1.0;
    x2 = 50.0;
    nb = nbmax;
    zbrak(x1, x2, n, xb1, xb2, nb);
    cout<<endl;
    cout<<"Roots of Bessj0:"<<endl;
    cout<<endl;
    cout<<"                  x              f(x)"<<endl;
    for (i = 1; i<=nb; i++) 
	{
        tol = (0.0000010) * (xb1[i] + xb2[i]) / 2.0;
        root =zbrent(xb1[i], xb2[i], tol);
        cout<< setw(8)<<"root "<<i;
        cout<< setw(12)<<root;
        cout<< setw(19)<<bessj0(root)<<endl;
    }
}

⌨️ 快捷键说明

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