Hi Anton, I have no problems in running your code. It is difficult to come with a diagnostic without more info on your error. I take this opportunity to AGAIN AND AGAIN request that the Root version number and the machine type be always specified in the mails to roottalk. In attachment, you will find two files: ring.cxx to be compiled aring.C an interactive macro these files are adaptations of your example and run without problems. Rene Brun Anton V. Bogomyagkov wrote: > > Hello, > I wrote a C++ code for drawing a function. I can compile it, but when I > try to execute the program error appears on the line where I define a > pointer to a TF1 class. However, canvas is drawing and function not. Below > is a code of my program. So, can somebody of you help me and explain what > is wrong there? > Thank you. > > #include <stdio.h> > #include <math.h> > #include "TROOT.h" > //#include "TClass.h" > //#include "TClassTable.h" > //#include "TCollection.h" > //#include "TObject.h" > #include "TCanvas.h" > #include "TMath.h" > #include "TF1.h" > #include "TApplication.h" > > extern void InitGui(); > VoidFuncPtr_t initfuncs[]={InitGui, 0}; > int Error; //needed by Motif > > TROOT root("hello","Hello World",initfuncs); > > Double_t ring(Double_t *x, Double_t *p) > { > Double_t Pi=3.14, Dl=0.005; > Double_t f=0, fx, phi,y,z; > if(p[2]){ > for(y=p[2];y<=p[3];y+=Dl){ > z=(x[0]-y)/p[1]; > fx=exp(-0.5*z*z)*sqrt(p[3]*p[3]-y*y); > f+=p[0]*fx*Dl; > } > > for(y=-p[3];y<=-p[2];y+=Dl){ > z=(x[0]-y)/p[1]; > fx=exp(-0.5*z*z)*sqrt(p[3]*p[3]-y*y); > f+=p[0]*fx*Dl; > } > > for(y=-p[2];y<=p[2];y+=Dl){ > z=(x[0]-y)/p[1]; > fx=exp(-0.5*z*z)*(sqrt(p[3]*p[3]-y*y)-sqrt(p[2]*p[2]-y*y)); > f+=p[0]*fx*Dl; > } > } > return f; > } > > int main(int argc, char **argv){ > > TApplication theApp("App",&argc,argv); > > TCanvas *c1 = new TCanvas("c1","Function draw",10,10,600,450); > c1->Show(); > > TF1 *func = new TF1("ring",ring,-6,6,4); > func->SetParameters(1500,0.3,1.7,1.71); > func->Draw(); > c1->Update(); > > theApp.Run(kTRUE); > > theApp.Run(); > > return 0; > } > Антон. Double_t ring(Double_t *x, Double_t *p) { Double_t Pi=3.14, Dl=0.005; Double_t f=0, fx, phi,y,z; if(p[2]){ for(y=p[2];y<=p[3];y+=Dl){ z=(x[0]-y)/p[1]; fx=exp(-0.5*z*z)*sqrt(p[3]*p[3]-y*y); f+=p[0]*fx*Dl; } for(y=-p[3];y<=-p[2];y+=Dl){ z=(x[0]-y)/p[1]; fx=exp(-0.5*z*z)*sqrt(p[3]*p[3]-y*y); f+=p[0]*fx*Dl; } for(y=-p[2];y<=p[2];y+=Dl){ z=(x[0]-y)/p[1]; fx=exp(-0.5*z*z)*(sqrt(p[3]*p[3]-y*y)-sqrt(p[2]*p[2]-y*y)); f+=p[0]*fx*Dl; } } return f; } void aring() { TCanvas *c1 = new TCanvas("c1","Function draw",10,10,600,450); TF1 *func = new TF1("ring",ring,-6,6,4); func->SetParameters(1500,0.3,1.7,1.71); func->Draw(); } #include <stdio.h> #include <math.h> #include "TROOT.h" #include "TCanvas.h" #include "TMath.h" #include "TF1.h" #include "TApplication.h" TROOT root("hello","Hello World"); Double_t ring(Double_t *x, Double_t *p) { Double_t Pi=3.14, Dl=0.005; Double_t f=0, fx, phi,y,z; if(p[2]){ for(y=p[2];y<=p[3];y+=Dl){ z=(x[0]-y)/p[1]; fx=exp(-0.5*z*z)*sqrt(p[3]*p[3]-y*y); f+=p[0]*fx*Dl; } for(y=-p[3];y<=-p[2];y+=Dl){ z=(x[0]-y)/p[1]; fx=exp(-0.5*z*z)*sqrt(p[3]*p[3]-y*y); f+=p[0]*fx*Dl; } for(y=-p[2];y<=p[2];y+=Dl){ z=(x[0]-y)/p[1]; fx=exp(-0.5*z*z)*(sqrt(p[3]*p[3]-y*y)-sqrt(p[2]*p[2]-y*y)); f+=p[0]*fx*Dl; } } return f; } int main(int argc, char **argv){ TApplication theApp("App",&argc,argv); TCanvas *c1 = new TCanvas("c1","Function draw",10,10,600,450); c1->Show(); TF1 *func = new TF1("ring",ring,-6,6,4); func->SetParameters(1500,0.3,1.7,1.71); func->Draw(); c1->Update(); theApp.Run(kTRUE); theApp.Run(); return 0; }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:44 MET