The probability density of the p-pulse for a particle is

\(\rho(p)=\frac{1}{4}\frac{a}{\pi\hbar}\Big[\frac{\sin{\frac{pa}{2\hbar}-\frac{n\pi}{2}}}{\frac{pa}{2\hbar}-\frac{n\pi}{2}}+(-1)^{n+1}\frac{\sin{\frac{pa}{2\hbar}+\frac{n\pi}{2}}}{\frac{pa}{2\hbar}+\frac{n\pi}{2}}\Big]^2\)

Write a program that calculates \(\rho\) with numerical values: a = 1.6, \(\hbar\) = 197, p = 0.07 and for n varying from 1 to \(n_{max}\).

 


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
	int n,nmax=10;
	double a,hb,p,pi=acos(-1.),pis2,x,y,u;
	a=1.6; hb=197.; p=0.07;
	pis2=pi/2.;
	x=p*a/2./hb;
	for(n=1;n<=nmax;n++)
	{
		y=n*pis2;
		u=sin(x-y)/(x-y)+pow(-1,n+1)*sin(x+y)/(x+y);
		printf("n=%d rho=%lg\n",n,a/pi/hb/4.*u*u);
	}
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Checking palindrome words using functions