# How to run function inside function

I can’t run this code on ROOT ! I know, first function is not consistent with derivativeFunc.C.

if I make it as “g++ derivaticeFunc.cpp -o derivativeFunc” , then it is not suitable for C++ due to “Math libraries”

Is there another way to run this script on ROOT ?

Thanks,
Cheers,
Ersel

[code]#include
#include “Math/Functor.h”
#include "Math/RichardsonDerivator.h"
using namespace std;

double myfunc(double x) {

return 2+3x+4sqrt(x,2);

}

int derivativeFunc () {

double x0 = 2;

ROOT::Math::Functor1D f1D(&myfunc);

ROOT::Math::RichardsonDerivator rd;
rd.SetFunction(f1D);

cout<<"Derivative of fucntion inheriting from "<<“IGenFunction f(x)=2+3x+4x^2 =2”<<endl;
cout<<"First Derivative : "<<rd.Derivative1(x0)<<endl;
cout<<"Second Derivative : "<<rd.Derivative2(x0)<<endl;
cout<<"Third Derivative : "<<rd.Derivative3(x0)<<endl;

return 0;

}
[/code]

Yes. if derivativeFunc.C is:

double myfunc(double x) {

return 2+3*x+4*TMath::Sqrt(x);

}

int derivativeFunc () {

double x0 = 2;

ROOT::Math::Functor1D f1D(&myfunc);

ROOT::Math::RichardsonDerivator rd;
rd.SetFunction(f1D);

cout<<"Derivative of fucntion inheriting from "<<"IGenFunction f(x)=2+3x+4x^2 =2"<<endl;
cout<<"First Derivative : "<<rd.Derivative1(x0)<<endl;
cout<<"Second Derivative : "<<rd.Derivative2(x0)<<endl;
cout<<"Third Derivative : "<<rd.Derivative3(x0)<<endl;

return 0;

}

do:

\$ root derivativeFunc.C

and you get:

root [0]
Processing derivativeFunc.C...
Derivative of fucntion inheriting from IGenFunction f(x)=2+3x+4x^2 =2
First Derivative : 4.41421
Second Derivative : -0.353553
Third Derivative : 0.265168

Many thanks