	program pith
	real l,m
C
C physics problem:  Two identical pith balls with mass m, carry an equal
C	charge q, and are suspended from a common point with an equal
C	length of string l.  The forces of electrostatic repulsion, gravity
C	and string tension balance, leaving the two balls seperated by
C	half angle theta.  Find theta given m,l, and q.
C
C		   3		     2
C		tan (theta)       C q
C find:	      -------------  =  ------
C		     2		      2
C	      1 + tan (theta)   4 mg l
C
C	We must now invert this function (which gives us q as a function
C	of theta) to give us theta as a function of q
C
C	We do this by using Newton's method to find zeros of the difference
C	bewteen the two quanties - i.e. values of theta that produce the
C	"correct" right-hand-side

	f(x)=x**3/(1.+x**2) - q**2*c/(4.*l**2*m*g)
	df(x)=x**2*(3.+x**2)/(1.+x**2)**2

	c=8.988e9	!Nm**2/C**2
	g=9.8		!m/s**2
	pi=3.1415926535

1	print 100
100	format('enter mass of pith ball in Kg ',$)
	read*,m
	print 101
101	format('enter length of string in m ',$)
	read*,l
	print 102
102	format('enter charge on pith balls in coulombs ',$)
	read*,q
	print 103
103	format('enter the maximum number of iterations and the tolerance ',$)
	read*,n,error
	print 104
104	format('enter your guess for the angle in degrees ',$)
	read*,theta

	x=tan(theta*pi/180.)

	do i=1,n
		dx= -f(x)/df(x)
		if(abs(dx).lt.error)goto 20
		x=x+dx
	enddo

	print*,'ERROR - exceeded maximum number of iterations'
	print*,'the final GUESS for'

20	theta=atan(x)
	print 200, theta*180./pi
200	format('the angle is ',f5.2,' degrees')
	print 201, i
201	format(i3, ' iterations were used')
	goto 1
	end
