jdkim
07-24-2009, 04:10 AM
Hi,
I was trying to make a figure of the Bessel function
with Microsoft Visual C++ 6.0 compiler.
My code is a simple combination of bessel.h and psplot.h
from NR3 as follows:
***********
#include "nr3.h"
#include "psplot.h"
#include "bessel.h"
Int main(void) {
const Int RES=500;
const Doub XLL=75., XUR=525., YLL=250., YUR=700.;
char *plotfilename = tmpnam(NULL);
VecDoub xx(RES), yy(RES);
Doub x1,x2;
Doub x3;
Int i;
Bessjy mybessel;
FILE *fp;
fp=fopen("test.txt","w");
for (;;) {
Doub ymax = -9.99e99, ymin = 9.99e99, del;
cout << endl << "Enter x1 x2 (x1=x2 to stop) :" << endl;
cin >> x1 >> x2;
if (x1==x2) break;
for (i=0;i<RES;i++) {
xx[i] = x1 + i*(x2-x1)/(RES-1.);
x3=xx[i];
yy[i] = mybessel.jn(0, x3);
fprintf(fp,"%f %f \n",xx[i],yy[i]);
if (yy[i] > ymax) ymax=yy[i];
if (yy[i] < ymin) ymin=yy[i];
}
del = 0.05*((ymax-ymin)+(ymax==ymin ? abs(ymax) : 0.));
PSpage pg(plotfilename);
PSplot plot(pg,XLL,XUR,YLL,YUR);
plot.setlimits(x1,x2,ymin-del,ymax+del);
plot.frame();
plot.autoscales();
plot.xlabel("x");
plot.ylabel("Bessel J_0(x)");
plot.setlinewidth(1.);
plot.lineplot(xx,yy);
if (ymax*ymin < 0.) plot.lineseg(x1,0.,x2,0.);
plot.display();
}
remove(plotfilename);
fclose(fp);
return 0;
}
**************
This code is not optimal. Anyway it was successfully compiled.
The figure showed nice up-down curve between 0 and 8.
But around x=8, there are abrupt changes.
In addition, if I increase the order n, the graph showed like a histogram.
I hope you have an answers for this.
Would you show me a track?
Thanks in advance.
jdkim
I was trying to make a figure of the Bessel function
with Microsoft Visual C++ 6.0 compiler.
My code is a simple combination of bessel.h and psplot.h
from NR3 as follows:
***********
#include "nr3.h"
#include "psplot.h"
#include "bessel.h"
Int main(void) {
const Int RES=500;
const Doub XLL=75., XUR=525., YLL=250., YUR=700.;
char *plotfilename = tmpnam(NULL);
VecDoub xx(RES), yy(RES);
Doub x1,x2;
Doub x3;
Int i;
Bessjy mybessel;
FILE *fp;
fp=fopen("test.txt","w");
for (;;) {
Doub ymax = -9.99e99, ymin = 9.99e99, del;
cout << endl << "Enter x1 x2 (x1=x2 to stop) :" << endl;
cin >> x1 >> x2;
if (x1==x2) break;
for (i=0;i<RES;i++) {
xx[i] = x1 + i*(x2-x1)/(RES-1.);
x3=xx[i];
yy[i] = mybessel.jn(0, x3);
fprintf(fp,"%f %f \n",xx[i],yy[i]);
if (yy[i] > ymax) ymax=yy[i];
if (yy[i] < ymin) ymin=yy[i];
}
del = 0.05*((ymax-ymin)+(ymax==ymin ? abs(ymax) : 0.));
PSpage pg(plotfilename);
PSplot plot(pg,XLL,XUR,YLL,YUR);
plot.setlimits(x1,x2,ymin-del,ymax+del);
plot.frame();
plot.autoscales();
plot.xlabel("x");
plot.ylabel("Bessel J_0(x)");
plot.setlinewidth(1.);
plot.lineplot(xx,yy);
if (ymax*ymin < 0.) plot.lineseg(x1,0.,x2,0.);
plot.display();
}
remove(plotfilename);
fclose(fp);
return 0;
}
**************
This code is not optimal. Anyway it was successfully compiled.
The figure showed nice up-down curve between 0 and 8.
But around x=8, there are abrupt changes.
In addition, if I increase the order n, the graph showed like a histogram.
I hope you have an answers for this.
Would you show me a track?
Thanks in advance.
jdkim