00001 void splines (Int_t np=23, Double_t a=-0.5, Double_t b=31)
00002 {
00003
00004
00005
00006
00007 Double_t *xx=0, *yy=0;
00008 TSpline3 *spline3=0;
00009 TSpline5 *spline5=0;
00010 TLine *line5, *line3;
00011 TText *text5, *text3, *textn;
00012 char text[20];
00013 const Double_t power=0.75;
00014
00015
00016 TF1 *f=new TF1("f","sin(x)*sin(x/10)",
00017 a-0.05*(b-a),b+0.05*(b-a));
00018
00019 f->Draw("lc");
00020
00021
00022 Float_t xx1, yy1, xx2, yy2, dx, dy;
00023 gPad->Update();
00024 gPad->GetRangeAxis(xx1,yy1,xx2,yy2);
00025 dx = xx2-xx1;
00026 dy = yy2-yy1;
00027 line5=new TLine(xx1+dx*0.3,yy1+dy*1.02,
00028 xx1+dx*0.38,yy1+dy*1.02);
00029 line5->SetLineColor(kRed);
00030 line5->SetLineWidth(2);
00031 text5 = new TText(xx1+dx*0.4,
00032 yy1+dy*1.03,"quintic spline");
00033 text5->SetTextAlign(12);
00034 text5->SetTextSize(0.04);
00035 line3=new TLine(xx1+dx*0.67,yy1+dy*1.02,
00036 xx1+dx*0.75,yy1+dy*1.02);
00037 line3->SetLineColor(kGreen);
00038 line3->SetLineWidth(2);
00039 text3 = new TText(xx1+dx*0.77,
00040 yy1+dy*1.03,"third spline");
00041 text3->SetTextAlign(12);
00042 text3->SetTextSize(0.04);
00043 textn = new TText(xx1+dx*0.8,yy1+dy*0.91," ");
00044 textn->SetTextAlign(12);
00045 textn->SetTextSize(0.04);
00046 textn->Draw();
00047
00048
00049 line5->Draw();
00050 text5->Draw();
00051 line3->Draw();
00052 text3->Draw();
00053
00054 for(Int_t nnp=2; nnp<=np; ++nnp) {
00055
00056
00057 if(xx) delete xx;
00058 xx = new Double_t[nnp];
00059 if(yy) delete yy;
00060 yy = new Double_t[nnp];
00061 for (Int_t i=0; i<nnp; ++i) {
00062 xx[i]=a+(b-a)*TMath::Power(i/Double_t (nnp-1),power);
00063 yy[i]=f->Eval(xx[i]);
00064 }
00065
00066
00067 Double_t eps=(b-a)*1.e-5;
00068 if(spline5) delete spline5;
00069 spline5 = new TSpline5("Test",xx,f,nnp,"b1e1b2e2",
00070 f->Derivative(a),f->Derivative(b),
00071 (f->Derivative(a+eps)-f->Derivative(a))/eps,
00072 (f->Derivative(b)-f->Derivative(b-eps))/eps);
00073
00074 spline5->SetLineColor(kRed);
00075 spline5->SetLineWidth(3);
00076
00077
00078 spline5->Draw("lcsame");
00079
00080
00081 if(spline3) delete spline3;
00082 spline3 = new TSpline3("Test",xx,yy,nnp,"b1e1",
00083 f->Derivative(a),f->Derivative(b));
00084
00085 spline3->SetLineColor(kGreen);
00086 spline3->SetLineWidth(3);
00087 spline3->SetMarkerColor(kBlue);
00088 spline3->SetMarkerStyle(20);
00089 spline3->SetMarkerSize(1.5);
00090
00091
00092 spline3->Draw("lcpsame");
00093
00094 sprintf(text,"%3d knots",nnp);
00095 textn->SetTitle(text);
00096 gPad->Update();
00097
00098
00099 gSystem->Sleep(500);
00100 }
00101 }