How to calculate radius of a sphere of Ideal gas? The problem I am faced with is approximating the mass of the sun, and I thought that a fancy approach would be to approximate the sun as being made up entirely of hydrogen atoms, finding the resulting radius of the sun, and calculating from thereon. Take $N$ hydrogen atoms and place them in a vacuum, and the gravitational force that exists between them will pull them together into a (non?)homogeneous sphere, where the gravitational force balances out the pressure that wants to push the sphere outwards. I thought that I could equate these two forces and be done with it, but from here on out I'm not too sure how to proceed. Bernoulli's equation: 
$$P + \rho g h + \frac{1}{2}\rho v^2 = C$$
does not seem to apply, as the gravitational acceleration $g$ varies over distance, and if I wanted to apply it I would have to integrate perhaps. Another approach I thought of was to use the ideal gas law:
$$PV = nRT$$
And take a spherical shell at radius $r$, find the difference in pressure acting to push the shell inwards and push the shell outwards, and equate this to the gravitational force, but even then I have my doubts. It also introduces a new element to consider, the temperature, which I am not too sure how to deal with. Is this the correct way forward?
P.S. This method is probably oversimplifying the problem and has no correlation to the sun's actual radius, at this point I am more interested in solving this theoretical problem. 
 A: Your overall method for determining the equilibrium for a star is correct. We use a combination of an assumed 'polytropic relation':
$$P = K \rho^{1+\frac{1}{n}}$$
and the requirement that this balances the gravitational pressure at a radius r (for a spherical shell of thickness $dr$):
$$4\pi r^2\frac{dP(r)}{dr} = -\frac{GM(r)}{r^2}4\pi r^2\rho(r)$$
where $M(r)$ is the mass enclosed by the shell. Using the polytropic equation together with the fact that $\frac{dM(r)}{dr} = 4\pi r^2\rho(r)$ gives a second order differential equation for $\rho(r)$, called the Lane-Emden equation. You can use the ideal gas law
$$P = \rho\frac{k_BT}{m}$$
where $m$ is the atomic mass of hydrogen, to determine the temperature $T(r)$. Some issues are that firstly, you will need to know $n$, and secondly, solutions are known only for some values of $n$.
For some solutions, there is a finite radius $R$, the radius of the star, for which the density goes to zero. It turns out that, for stars like our sun, $n=3$ is a good model, and there is a finite radius. However, an exact (analytic) solution is unknown.
As a special case, if you take $n\rightarrow\infty$ in the polytropic equation, essentially giving the ideal gas equation itself, with the assumption of constant temperature throughout the star, the solution is called an "isothermal sphere" - but this does not model the sun very well.
For the general case, knowing this radius $R$ (assuming you want the experimental value), you can plug in the integration constants to get $\rho(r)$, and the mass is simply
$$M = \int_{0}^{R}4\pi r^2\rho(r)dr$$
Also note that you will need one of the total mass or the radius of the star to find the other.
A: The basic idea you're reaching for here is called hydrostatic equilibrium. That is, gravitational forces are balanced by pressure gradients. In a context like geophysical fluid dynamics, you'll encounter hydrostatic equilibrium written as $${\partial P\over\partial z} = -\rho g, $$ but as you point out when you bring up Bernoulli's equation, that won't work in this case, as $g$ depends on the radius of the star (or height $z$ in the equation above).
If you're keeping things non-relativistic, you can generalize to non-constant $g$ by simply substituting in Newton's law of gravitation. Also, since we're talking about spherical distributions, it seems better to write this in terms of a radius than a height, so we'll change $z$ to $r$:
$${\partial P\over \partial r} = -{GM(r)\rho(r)\over r^2}, $$
with $M(r)$ being the amount of mass closer to the center of the sphere than the point at which you're calculating the pressure gradient. Mathematically, we would write $$M(r) = 4\pi\int_0^r \rho(r')r'^2 dr'.$$
Now, we still don't quite have the solution you are looking for, because we don't know how to write $\rho(r)$. The simplest choice would be to let $\rho$ be constant, but that isn't a good choice in this case, for two reasons: (a) it's nowhere near the truth, and (b) it requires you to know what you're trying to estimate (i.e., the total mass of the sun).
Instead, we ought to employ an equation of state, which will allow us to write $\rho(P)$ instead of $\rho(r)$.  The second equation you have tried to use, the ideal gas law, is an equation of state, and you could certainly use it, but the core assumption it makes (that the gas molecules are non-interacting) isn't particularly valid at the temperatures and densities one finds inside stars.  The Van der Waals equation $$\left(p+{n^2a\over V^2}\right)\left(V-nb\right)=nRT,$$
is probably a better choice though even that isn't perfect. The actual equation of state for any given star depends on its composition (largely because the details of what kinds of fusion are going on in the core make a difference in the temperature, pressure, and density profiles).
In any case, you're going to need to do something about the temperature. Again, the simplest choice you could make is to pick a constant temperature, and while that's not a particularly great approximation, it's not a crazy thing to do, either (at least, not for the problem you're working on).  Working out the temperature in detail is a complicated problem, as you're trying to balance the energy input from nuclear fusion in the core with radiation at the surface (these are the easy part) while correctly dealing with the heat transport through the bulk of the star (that's the hard part).
That should be enough to get you to an answer, though I'm not sure how good of an answer it will be.
Four more (very brief) points:


*

*Spherical distributions of gas don't really have a well-defined surface, so you'll have to make a choice about where the sun "ends" and the space around it "begins".

*If you're looking at cooler objects (like gas giant planets, instead of stars) the temperature issues get a little simpler, but even there assuming a constant temperature isn't a great approximation.

*This is all non-relativistic. There is a relativistic version of the hydrostatic balance equation, called the Tolman-Oppenheimer-Volkoff equation, which is (obviously) a bit more complicated.

*Though it's outside the scope of your question, really dense objects like neutron stars have an additional source of pressure which is purely quantum mechanical (usually called "degeneracy pressure"). It acts outward, rather than inward, and would obviously change the above discussion quite a bit.
