Revision as of 08:40, 1 December 2018 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Original file(1,618 × 996 pixels, file size: 144 KB, MIME type: image/jpeg)

Test of implementation of function kori through the built-in C++ function j0.

for various values of the argument $x$, function kori can be expressed with

kori$(x)=\displaystyle \frac{J_0\big(L_1 \sqrt{x}\big)}{1-x}$

where $L_1$ is first zero of the Bessel function function $j_0$. This function, BesselJ0, is denoted in C++ with identifier j0. The straightforward implementation is good for positive values of argument, larger than 2; for smaller, but still positive values of the argument, the representation is not good; for other values (negative and complex) this implementation fails.

The following special expansion is used:

kori$(x)=\,$ $\displaystyle \big(1\!-\!x/M_2\big)\big(1\!-\!x/M_3\big) \sum_{n=0}^{\infty}$ $ c_n x^n$

where $M_m=(L_m/L_1)^2$, and $L_n$ is $n$th zero of function BesselJ0. The coefficients $c$ are evaluated using the Mathematica routine Series; approximations for these coefficients can be extracted from the C++ code below.

The series is truncated at the term with $n=15$, as it is sufficient for the numerical implementation for $-M_2<x\le M_2$ with at least 15 significant figures.

The thick red curve shows the implementation of function kori through the truncated series above. The thin black curve shows the implementation through the built-in function j0; it fully overlaps with the red curve, but can be seen at the strong zooming–in. In order to make the difference visible, deviation

$\mathcal D(x)= (1\!-\!x/M_2)(1\!-\!x/M_3) \sum_{n=0}^{15}$ $ c_n x^n - \, $j0$(L1*\mathrm{sqrt}(x))/(1\!-\!x)$

is shown with another thin black curve. In order to make it visible, it is scaled with factor $10^{15}$, as it is marked in the figure.

Deviation $\mathcal D(x)$ is of order of $10^{-15}$ or even $10^{-14}$, while $0\!<\!x\!<\!2$; this can be attributed to the rounding errors at evaluation of function double j0(double). For $x\!=\!1$, the representation through j0 just fails, and this is the main motivation to built-up the independent implementation of function kori. In order to keep the code transparent and easy for the reading by human, it is preferably to cover the range from $0$ to $M_2$ with single–peace approximation; such a single-peace approximations have advantages also for the numerical evaluation of the contour integrals.

Deviation is of order of $10^{-16}$ for $2\!<\!x\!<6$, and this verifies each of the representations mentioned.

Deviation grows–up at $x\!>\!6$, but still can be used to plot graphics at least until the next zero of function kori, which is $M_2$.

The comparison shows, that in the range $0<x<M_1\approx 5.3$, the implementation kori0 with 15 terms,

kori0$(x)= (1\!-\!x/M_2)(1\!-\!x/M_3) \sum_{n=0}^{15} c_n x^n$

is better than the straightforward implementation through the built-in function j0.

Approximation kori0 is expected to be used for evaluation of integrals expressed through function kori.

C++ generator of curves

#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
//using namespace std;
#include <complex>
typedef std::complex<double> z_type;
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)
#define M(x,y) fprintf(o,"%6.4lf %6.4lf M\n",0.+x,0.+y);
#define L(x,y) fprintf(o,"%6.4lf %6.4lf L\n",0.+x,0.+y);

// #include "korifit76.cin"
#include "ado.cin"

long double L= 2.4048255576957727686216318793265 ;

DB LN[9]={ 0., 2.404825557695773, 5.5200781102863115,
18.071063967910924,21.21163662987926, 24.352471530749302};

long double kori0(long double x){ int n,m; long double s;
long double c[16]={1,
s=c[m]*x; for(n=m-1;n>0;n--) {s+=c[n]; s*=x;}
return (1+s)*(1-(long double)0.189791479516754136723328431595*x); }

double korid(double x){ int n,m; double s;
double c[16]={1,
s=c[m]*x; for(n=m-1;n>0;n--) {s+=c[n]; s*=x;}
return (1+s)*(1-0.189791479516754136723328431595*x); }

int main(){int m,n,i; double x,y,z,t,u; FILE *o;
long double X,Y,Z,T,U;

fprintf(o,"20 200 translate 100 100 scale 2 setlinecap 1 setlinejoin\n");

for(m=0;m<11;m+=1) {M(m,0)L(m,2)}
fprintf(o,"0.007 W S\n");

for(m=2;m<4;m++){ x=LN[m]/LN[1]; x*=x; M(x,0)L(x,1) }
fprintf(o,"0.004 W 1 0 1 RGB S\n");

for(n=0;n<1060;n+=10){ x=-.3+.01*n; y=kori0(x); if(n==0) M(x,y) else L(x,y);} fprintf(o,"1 0 0 RGB .03 W S\n");

for(n=0;n<1040;n+=10){ x=.01*(n+.5); y=j0(L*sqrt(x))/(1.-x); if(n==0) M(x,y) else L(x,y);} fprintf(o,"0 0 0 RGB .01 W S\n");

//for(n=0;n<720;n+=1){ x=.01*(n+.5); y=korid(x)-j0(L*sqrt(x))/(1.-x); y*=1.e15; if(n==0) M(x,y) else L(x,y);}
//fprintf(o,"0 0 1 RGB .0009 W S\n");

for(n=0;n<720;n+=1){ X=(long double).01*(n+(long double).5); x=(double)X;
                        U=T*1.e15; u=(double)U; y=u;if(n==0) M(x,y) else L(x,y);}
fprintf(o,"0 0 1 RGB .0008 W S\n");

for(n=0;n<730;n+=1){ X=(long double).01*(n+(long double).5); x=(double)X;
                        Z=(long double)j0(L*sqrt(x))/(1.-x);
                        U=T*1.e15; u=(double)U; y=u;if(n==0) M(x,y) else L(x,y);}
fprintf(o,"0 0 0 RGB .0008 W S\n");

fprintf(o,"showpage\n%c%cTrailer\n",'%','%'); fclose(o);
system("epstopdf koritestplo.eps");
system( "open koritestplo.pdf");
return 0;}

Latex generator of labels

%\paperwidth 570pt
\paperwidth 780pt
%\paperheight 138pt
\paperheight 480pt
\textwidth 420pt
\textheight 600pt
\topmargin -108pt
\oddsidemargin -72pt
\newcommand \ds {\displaystyle}
\newcommand \sx {\scalebox}
\newcommand \rme {\mathrm{e}}
\newcommand \rot {\begin{rotate}}
\newcommand \ero {\end{rotate}}
\newcommand \ing {\includegraphics}
\parindent 0pt
\put( 14,190){\sx{2.8}{$0$}}
\put(170,278){\rot{-12}\sx{2.8}{$y\!=\! \mathrm{kori}(x)$}\ero}
\put(598,468){\rot{0}\sx{2.8}{$y\!=\! 10^{15}\,\mathcal D(x)$}\ero}
%\put(656,148){\rot{65}\sx{2.8}{$y\!=\! 10^{15}\,\mathcal D(x)$}\ero}


File history

Click on a date/time to view the file as it appeared at that time.

current06:12, 1 December 2018Thumbnail for version as of 06:12, 1 December 20181,618 × 996 (144 KB)Maintenance script (talk | contribs)Importing image file
  • You cannot overwrite this file.

The following page links to this file: