kutta
01-29-2009, 09:25 PM
Hello Comrades
Shall be glad to receive your solution for this Template class
function as the same requires proper initiation of the variables.
As Initition procedure is different from that of an ordinary type and template type of functions,
your try is sought with plethora of thanks.
Though simple but gets complicated with too many parametres
Thats why time and again i have been wanting if somebody suggests an universal way of tackling initiating proplems or any body can alogorithamise(if at all this verbaal request is apt) the same enabling for quick use of initialising..
the same .
#include "nr3.h"
#include <iomanip.h>
#include <iostream>
#include <algorithm>
#include <functional>
#define func
using namespace std;
template <class T>
Bool zbrac(T &func, Doub &x1, Doub &x2)
{
const Int NTRY=50;
const Doub FACTOR=1.6;
if (x1 == x2) throw("Bad initial range in zbrac");
Doub f1=func(x1);
Doub f2=func(x2);
for (Int j=0;j<NTRY;j++) {
if (f1*f2 < 0.0) return true;
if (abs(f1) < abs(f2))
f1=func(x1 += FACTOR*(x1-x2));
else
f2=func(x2 += FACTOR*(x2-x1));
}
return false;
}
int main()
{
Doub x1[3]={3.4,6.7,8.9};
Doub x2[3]={1.2,3.5,5.6};
Doub f1;//= func(x1);
Doub f2;//= func(x2);
//zbrac(f1,3,3);
cout << "Bracketed X1-array";
for(int i=0;i,3;i++)
cout << x1[i] << " ";
cout << endl;
//zbrac(f2,3,3);
cout << "Bracketed -y array";
for(int j =0;j< 3;j++)
cout << x2[j] << " " ;
cout << endl;
"zbrac(func,6.7,3.5)";
return 0;
}
/**
The output is as follows though it is incomplete inlieu of its void function
since its declaration is vague in the above example;
Bracketed X1-array3.4 6.7 8.9 4.24399e-314 1.09719e+270 1.78797e-307 4.98786e-30
6 -1.#QNAN 2.31288e-306 4.98617e-306 5.56268e-307 1.78811e-307 2.71615e-311 -1.5
4428 -5.02206e-301 2.58465e+161 -7.41456e-304 2.58472e+161 3.68421e+180 5.68175e
-322 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -3.58008e-301 -7.53703e+0
06 1.78807e-307 1.59123e-314 1.66227e+024 5.56268e-307 -1.75139 1.59122e-314 -1.
54396 1.80501e-313 1.07413e-314 0 0 0 0 0 0 0 0 1.31719e-309 2.31408e-306 -1.#QN
AN 1.07413e-314 -4.3711e-282 1.59126e-314
*/.
Thanking you
As
Kutta(C.R.Muthukumar)
:)
Shall be glad to receive your solution for this Template class
function as the same requires proper initiation of the variables.
As Initition procedure is different from that of an ordinary type and template type of functions,
your try is sought with plethora of thanks.
Though simple but gets complicated with too many parametres
Thats why time and again i have been wanting if somebody suggests an universal way of tackling initiating proplems or any body can alogorithamise(if at all this verbaal request is apt) the same enabling for quick use of initialising..
the same .
#include "nr3.h"
#include <iomanip.h>
#include <iostream>
#include <algorithm>
#include <functional>
#define func
using namespace std;
template <class T>
Bool zbrac(T &func, Doub &x1, Doub &x2)
{
const Int NTRY=50;
const Doub FACTOR=1.6;
if (x1 == x2) throw("Bad initial range in zbrac");
Doub f1=func(x1);
Doub f2=func(x2);
for (Int j=0;j<NTRY;j++) {
if (f1*f2 < 0.0) return true;
if (abs(f1) < abs(f2))
f1=func(x1 += FACTOR*(x1-x2));
else
f2=func(x2 += FACTOR*(x2-x1));
}
return false;
}
int main()
{
Doub x1[3]={3.4,6.7,8.9};
Doub x2[3]={1.2,3.5,5.6};
Doub f1;//= func(x1);
Doub f2;//= func(x2);
//zbrac(f1,3,3);
cout << "Bracketed X1-array";
for(int i=0;i,3;i++)
cout << x1[i] << " ";
cout << endl;
//zbrac(f2,3,3);
cout << "Bracketed -y array";
for(int j =0;j< 3;j++)
cout << x2[j] << " " ;
cout << endl;
"zbrac(func,6.7,3.5)";
return 0;
}
/**
The output is as follows though it is incomplete inlieu of its void function
since its declaration is vague in the above example;
Bracketed X1-array3.4 6.7 8.9 4.24399e-314 1.09719e+270 1.78797e-307 4.98786e-30
6 -1.#QNAN 2.31288e-306 4.98617e-306 5.56268e-307 1.78811e-307 2.71615e-311 -1.5
4428 -5.02206e-301 2.58465e+161 -7.41456e-304 2.58472e+161 3.68421e+180 5.68175e
-322 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -3.58008e-301 -7.53703e+0
06 1.78807e-307 1.59123e-314 1.66227e+024 5.56268e-307 -1.75139 1.59122e-314 -1.
54396 1.80501e-313 1.07413e-314 0 0 0 0 0 0 0 0 1.31719e-309 2.31408e-306 -1.#QN
AN 1.07413e-314 -4.3711e-282 1.59126e-314
*/.
Thanking you
As
Kutta(C.R.Muthukumar)
:)