The illumination of the diffaction ratio of two slots is given, according to the position \(x\) in this figure, by the formula \(E=4E_0\cos^2{\frac{\pi ex}{\lambda f}}(\frac{\sin{\frac{\pi ax}{\lambda f}}}{\frac{\pi ax}{\lambda f}})^2\)

  • \(E_0\) illumination obtained with a single slot (\(1 W.m^{-2}\))
  • \(a\) common width of the two slots (\(100 \mu\))
  • \(e\) distance from the vertical axes of the two slots (\(600 \mu\))
  • \(\lambda\) wavelength of light used (\(0.63 \mu)\)
  • \(f\) focal length of the lens (\(250 mm\)).

Write a program calculating this illumination for \(x\) ranging from -5.5 to 5.5 mm in steps of 1 mm, without using the pow function.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
	int i,n;
	double E0,p,pi=acos(-1.),l,f,u,e,v,a,x,c,r,s;
	
	E0=1.; a=100.; e=600.; l=0.63; f=250.;
	n=11;
	p=pi/l/f; u=p*e; v=p*a;
	for(i=0;i<=n;i++)
	{
		x=-5.5+i;
		c=cos(u*x);
		r=v*x; 
		if(r==0.) 
			s=1.; 
		else 
			s=sin(r)/r;
		printf("x=%lf E=%lf\n",x,4*E0*c*c*s*s);
	}
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Number of occurrence of a string into another one