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

📄 d4r25.cpp

📁 数值计算c++源代码,包括各种算法。很有用的。
💻 CPP
字号:
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
#include <stdlib.h>
#include <fstream.h>
#include <string>
#include <process.h>

double bessi0(double x)
{
	double p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9;
	double y,aaa,bbb,ax,temp;
    p1 = 1.0;             p2 = 3.5156229;
    p3 = 3.0899424;       p4 = 1.2067492;
    p5 = 0.2659732;       p6 = 0.0360768;
    p7 = 0.0045813;
    q1 = 0.39894228;      q2 = 0.01328592;
    q3 = 0.00225319;      q4 = -0.00157565;
    q5 = 0.00916281;      q6 = -0.02057706;
    q7 = 0.02635537;      q8 = -0.01647633;
    q9 = 0.00392377;
    if( fabs(x) < 3.75)
	{
        y = (x / 3.75)*(x / 3.75);
        aaa = y * (p5 + y * (p6 + y * p7));
        temp = p1 + y * (p2 + y * (p3 + y * (p4 + aaa)));
	}
    else
	{
        ax = fabs(x);
        y = 3.75 / ax;
        aaa = exp(ax) / sqrt(ax);
        bbb = q4 + y * (q5 + y * (q6 + y * (q7 + y * (q8 + y * q9))));
        temp = aaa * (q1 + y * (q2 + y * (q3 + y * bbb)));
	}
	return temp;
}

double bessi(int n, double x)
{
	int j,m;
	double iacc,bigno,bigni,tox,bip,bi,temp;
	double bim;
    iacc = 40;
    bigno = 10000000000.0;
    bigni = 0.0000000001;
    if (n < 2)cout<<"bad argument n in bessi";
    tox = 2.0 / x;
    bip = 0.0;
    bi = 1.0;
    temp = 0.0;
    m = 2 * ((n + int(sqrt(iacc * n))));
    for( j = m;j>=1;j--)
	{
        bim = bip + j * tox * bi;
        bip = bi;
        bi = bim;
        if (fabs(bi) > bigno) 
		{
            temp = temp * bigni;
            bi = bi * bigni;
            bip = bip * bigni;
        }
        if( j == n) temp = bip;
	} 
    temp = temp * bessi0(x) / bi;
	return temp;
}

void main()
{
    //program d4r25
    //driver for routine bessi
    int i,n;
	char text[20];
    double nval,value,x; 
    const double pi = 3.1415926;
    fstream fin;
    fin.open("d:\\vc常用数值算法集\\data\\fncval.dat",ios::in);
    while ( strcmp(text,"In,")!=0 ) 
	{
      fin>>text;
	}
	fin>>text;
    fin>>nval; 
    fin>>text;
	cout<<"Modified Bessel Function In "<<endl;
    cout<<endl;
    cout<<"      n      x          actual          bessi(n,x)"<<endl;
    for( i = 1; i<=nval; i++)
	{
		fin>>n;
        fin>>x;
		fin>>value;  
		cout<<setprecision(2)<<setw(6)<<n;
		cout<<setprecision(2)<<setw(7)<<x;
        cout<<setprecision(6)<<setw(18)<<value;
		cout<<setprecision(6)<<setw(18)<<bessi(n,x)<<endl;			          
    }
}

⌨️ 快捷键说明

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