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

📄 d4r16.cpp

📁 Visual C++ 常用数值算法集 源代码
💻 CPP
字号:
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
#include <stdlib.h>
#include <fstream.h>
#include <string>
#include <process.h>

int sgn(double x)
{
	int temp;
	if(x>0) temp=1;
	if(x=0) temp=0;
	if(x<0) temp=-1;
	return temp;
}

double bessj1(double x)
{
	double p1,p2,p3,p4,p5,q1,q2,q3,q4,q5;
	double r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,s5,s6;
	double bbb,ccc,aaa,temp,ax,xx,z,y;
    r1 = 72362614232.0;           r2 = -7895059235.0;
    r3 = 242396853.1;             r4 = -2972611.439;
    r5 = 15704.4826;              r6 = -30.16036606;
    s1 = 144725228442.0;          s2 = 2300535178.0;
    s3 = 18583304.74;             s4 = 99447.43394;
    s5 = 376.9991397;             s6 = 1.0;
    p1 = 1.0;                     p2 = 0.00183105;
    p3 = -0.00003516396496;       p4 = 0.000002457520174;
    p5 = -0.000000240337019;
    q1 = 0.04687499995;           q2 = -0.0002002690873;
    q3 = 0.000008449199096;       q4 = -0.00000088228987;
    q5 = 0.000000105787412;
    if (fabs(x) < 8.0 )
	{
        y = x*x;
        aaa = r1 + y * (r2 + y * (r3 + y * (r4 + y * (r5 + y * r6))));
        bbb = s1 + y * (s2 + y * (s3 + y * (s4 + y * (s5 + y * s6))));
        temp = x * aaa / bbb;
	}
    else
	{
        ax = fabs(x);
        z = 8.0 / ax;
        y = z*z;;
        xx = ax - 2.356194491;
        aaa = p1 + y * (p2 + y * (p3 + y * (p4 + y * p5)));
        bbb = q1 + y * (q2 + y * (q3 + y * (q4 + y * q5)));
        ccc = sqrt(0.636619772 / ax);
        temp = ccc * (cos(xx) * aaa - z * sin(xx) * bbb * sgn(x));
	}  
	return temp;
}

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

⌨️ 快捷键说明

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