# Need Fortran code to solve simple physics prob using bisection method

## Problem

Find the distance `x` on the axis perpendicular to the center of a ring of radius `R = 0.1 m` and total charge `Q = 1e-6 C` such that a point charge `q = 1e-9 C` located at `x` experiences a force of `F_target = 5.1 N`.

## Solution

The following program uses the Bisection Method to solve for `x`. The program assumes a Coulomb constant of `k = 9e9` and permittivity of free space of `e = 8.9e-12`:

``````program ring_force_bisection
implicit none

real :: k, Q, q, R, F_target
real :: a, b, c, x, Fx, Fa, Fb

! Coulomb constant k = 9e9
! Total charge on ring (in C) Q = 1e-6
! Point charge (in C) q = 1e-9
! Radius of ring (in m) R = 0.1
! Target force (in N) F_target = 5.1
! Initial guesses for x a = 0.01 b = 0.2

! Evaluate F(a) and F(b)
Fa = k*Q*q*a / ((a**2) + (R**2))**1.5
Fb = k*Q*q*b / ((b**2) + (R**2))**1.5

! Bisection method
do while (b - a > 1e-6)
! Compute midpoint
c = (a + b) / 2

! Evaluate F(c)
Fx = k*Q*q*c / ((c**2) + (R**2))**1.5

! Check sign of F(c) and update a or b
if (Fx*Fa > 0) then
a = c
Fa = Fx
else
b = c
Fb = Fx
endif
end do

! Compute final value of x
x = (a + b) / 2

! Print result
write(_,_) "The distance x where the force is 5.1 N is:", x, "m"

contains
The distance `x` where the force is 5.1 N is approximately 0.033 m.