Is there a recursive, iterative way to determine a value with a given condition?

I wrote a program intended to calculate the plasma beta of a hydrostatic solar atmosphere:

B_0 = 0.02 # base magnetic field [T]
p_0 = 0.015 # base pressure [J/m^-3]
h_D = 7.5E7 # dipole depth [m]
R_☉ = 6.96E8 # solar radius [m]
M_☉ = 1.9891E30 # solar mass [kg]
G = 6.673E-11 # gravitational constant [m^3 kg^-1 s^-2]
μ = 0.61 # mean molecular weight of solar corona
m_H = 1.6726E-27 # mass of H particle [kg]
μ_0 = (4*pi)*10^(-7) # permeability [H/m]
k = 1.3806E-23 # boltzmann constant [J/K]
T = 1E6 # temperature [K]

g = (G*M_☉)/(R_☉^2)

lambda_p = (k*T)/(μ*m_H*g)    # coronal scale height for 1MK [m]

p(h) = p_0*exp(-h/lambda_p)
B(h) = B_0*(1 + (h/h_D))^(-3)

beta = p(h)/(B(h)^2 / (2*μ_0) )

I am not very familiar with using iterative/numerical methods and was wondering if there was a way to determine the value of h when beta = 1?


you could use Roots.jl

using Roots
function beta(h)
  return p(h)/(B(h)^2 / (2*μ_0) )
end

f0 = h-> beta(h) - 1
Roots.find_zero(f0,2*h_D) # -2.3540849742856756e8