Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
slits.C
Go to the documentation of this file.
1// Example drawing the interference pattern of light
2// falling on a grid with n slits and ratio r of slit
3// width over distance between slits.
4
5auto pi = TMath::Pi();
6
7// function code in C
8double single(double *x, double *par) {
9 return pow(sin(pi*par[0]*x[0])/(pi*par[0]*x[0]),2);
10}
11
12double nslit0(double *x,double *par){
13 return pow(sin(pi*par[1]*x[0])/sin(pi*x[0]),2);
14}
15
16double nslit(double *x, double *par){
17 return single(x,par) * nslit0(x,par);
18}
19
20// This is the main program
21void slits() {
22 float r,ns;
23
24 // request user input
25 cout << "slit width / g ? ";
26 scanf("%f",&r);
27 cout << "# of slits? ";
28 scanf("%f",&ns);
29 cout <<"interference pattern for "<< ns
30 <<" slits, width/distance: "<<r<<endl;
31
32 // define function and set options
33 TF1 *Fnslit = new TF1("Fnslit",nslit,-5.001,5.,2);
34 Fnslit->SetNpx(500);
35
36 // set parameters, as read in above
37 Fnslit->SetParameter(0,r);
38 Fnslit->SetParameter(1,ns);
39
40 // draw the interference pattern for a grid with n slits
41 Fnslit->Draw();
42}
ROOT::R::TRInterface & r
Definition Object.C:4
1-Dim function class
Definition TF1.h:182
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition TF1.cxx:3488
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF1.cxx:1340
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:608
Double_t x[n]
Definition legend1.C:17
constexpr Double_t Pi()
Definition TMath.h:40
void slits()
Definition slits.C:21
double nslit(double *x, double *par)
Definition slits.C:16
double single(double *x, double *par)
Definition slits.C:8
auto pi
Definition slits.C:5
double nslit0(double *x, double *par)
Definition slits.C:12