Visual C++ 常用数值算法集 源代码
源代码在线查看: d11r4.cpp
#include "iostream.h"
#include "math.h"
#include "stdlib.h"
double func(double x)
{
return bessj0(x);
}
double deriv(double x)
{
return -bessj1(x);
}
void main()
{
//program d11r4
//driver for routine dbrent
double dbr,ax,bx,cx,fa,fb,fc,tol = 0.000001;
double xmin;
double eql = 0.0001;
double amin[21];
int iflag,i,nmin = 0;
cout cout cout cout cout.setf(ios::fixed|ios::left);
cout.precision(6);
for (i = 1; i {
ax = i;
bx = i + 1.0;
mnbrak(ax, bx, cx, fa, fb, fc);
dbr = dbrent(ax, bx, cx, tol, xmin);
if (nmin == 0)
{
amin[1] = xmin;
nmin = 1;
cout cout.width(14); cout cout.width(14); cout cout.width(14); cout cout.width(14); cout cout }
else
{
iflag = 0;
for (int j = 1; j {
if (fabs(xmin - amin[j]) {
iflag = 1;
}
}
if (iflag == 0)
{
nmin = nmin + 1;
amin[nmin] = xmin;
cout cout.width(14); cout cout.width(14); cout cout.width(14); cout cout.width(14); cout cout }
}
}
}