forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slits.C
42 lines (33 loc) · 1018 Bytes
/
slits.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Example drawing the interference pattern of light
// falling on a grid with n slits and ratio r of slit
// width over distance between slits.
auto pi = TMath::Pi();
// function code in C
double single(double *x, double *par) {
return pow(sin(pi*par[0]*x[0])/(pi*par[0]*x[0]),2);
}
double nslit0(double *x,double *par){
return pow(sin(pi*par[1]*x[0])/sin(pi*x[0]),2);
}
double nslit(double *x, double *par){
return single(x,par) * nslit0(x,par);
}
// This is the main program
void slits() {
float r,ns;
// request user input
cout << "slit width / g ? ";
scanf("%f",&r);
cout << "# of slits? ";
scanf("%f",&ns);
cout <<"interference pattern for "<< ns
<<" slits, width/distance: "<<r<<endl;
// define function and set options
TF1 *Fnslit = new TF1("Fnslit",nslit,-5.001,5.,2);
Fnslit->SetNpx(500);
// set parameters, as read in above
Fnslit->SetParameter(0,r);
Fnslit->SetParameter(1,ns);
// draw the interference pattern for a grid with n slits
Fnslit->Draw();
}