Demo entry 6357650

c++

   

Submitted by gms on Apr 23, 2017 at 15:10
Language: C++. Code size: 1.7 kB.

#include<iostream>
#include<math.h>
#include <complex>
#include<stdlib.h>
#include <fstream>
#include <iomanip>
using namespace std;
complex<double> bessel(int n, complex<double> x);
double besseli(int n, double x);
double besselj(int n, double x);

void main()
{
   complex<double> x,i(0,1);
   double max=0,y=0,a,b;
   int n;
   ofstream file;
   file.open("bessel.dat");

   for (a = 500; a <= 600; a++)
   {
      for (b = 500; b <= 600; b++)
      {
         n = 0;
         y = abs(bessel(n, a+b*i));
         while ((y > max*10e-7) || (y > 10e-7))
         {
            n++;
            y = abs(bessel(n, a/10+b/10*i));
            if (y > max) max = y;
         }
         //file << setprecision(8);
         file << a/10<<'\t'<<b/10<<'\t'<<n << endl;
      }
   }
   file.close();
   system("pause");
}

double besseli(int n, double x)
{
   int i, m;
   double p, y, t, s, b0, b1, besse0;
   double a[7] = {
      1.0,3.5156229,3.0899424,1.2067492,0.2659732,0.360768e-001,0.45813e-002
   };
   double b[7] = {
      0.5,0.87890594,0.51498869,0.15084934,0.2658733e-001,0.301532e-002,0.32411e-003
   };
   double c[9] = { 0.39894228,0.1328592e-001,0.225319e-002,-0.157565e-002,0.916281e-002,
      -0.2057706e-001,0.2635537e-001,-0.1647633e-001,0.392377e-002
   };
   double d[9] = {
      0.39894228,-0.3988024e-001,-0.362018e-002,0.163801e-002,-0.1031555e-001,0.2282967e-001,
      -0.2895312e-001,0.1787654e-001,-0.420059e-002
   };

   t = fabs(x);
   if (n<0) n = -n;
   if (n == 1)
   {
      if (t<3.75)//i1
      {
         y = (t / 3.75)*(t / 3.75); p = b[6];
         for (i = 5; i >= 0; i--)
         {
            p = p*y + b[i];
         }
         p = p*x;

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).