// 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: "<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(); }