Hi,
You are missing a statement
return returnValue;
in your function flux. You have other problems as well in your code.
Rene Brun
Datao Gong wrote:
>
> Hi,Everyone,
> I just need to caculate some function values. Also it should not be hard
> to draw the funcation. But the Root always complain divided by zero.
> If i do not call the function in the loop, it is fine and get what i
> expect value. Since my code is rathen simple. i paste it here. I use
> Root 3.03 on osf1 system.
>
> #include "TH1.h"
> #include "TF1.h"
> #include "TROOT.h"
> #include "TStyle.h"
>
> Double_t f(Double_t z)
> {
>
> Double_t returnValue = (1+0.5*z)*(1+0.5*z)*TMath::log(1/z)-
> 0.5*(1-z)*(3+z);
> return returnValue;
>
> }
>
> Double_t fluxMR(Double_t beam,Double_t m)
> {
> Double_t s = 4*beam*beam;
> Double_t me = 0.511/1000.0;
> Double_t alpha = 1/137.036;
>
> Double_t returnValue;
>
> Double_t z = m*m/s;
>
> Double_t t1 = TMath::log(s/(me*me))-1;
> Double_t t2 = TMath::log(s/(m*m));
> returnValue = 3*8*alpha*alpha/(m*m*m)*
> ( f(z)*t1*t1-1/3.0*t2*t2*t2 );
>
> }
>
> Double_t flux(Double_t *beam, Double_t *par)
> {
>
> Double_t etacM = par[0];
> Double_t etacPrimeM = par[1];
> Double_t returnValue = fluxMR(beam[0],etacPrimeM)/fluxMR(beam[0],etacM);
> return returnValue;
>
> }
>
> void calcflux()
> {
> Double_t par[2];
> Double_t beam[1];
> beam[0] = 5.28;
> par[0] = 2.98;
> par[1] = 3.64;
>
> Double_t res;
> for(Int_t i = 0 ; i < 100 ; ++i){ //if do not loop, it is fine.
> beam[0] = 4.7;
> // beam[0] = 4.7+(5.5-4.7)/100.0*i;
> cout<<flux(beam,par)<<endl;
>
> }
> }
>
> Thanks
>
> Gong Datao
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET