# Accurate way to programmatically generate a main sequence star?

I am working on a (personal) programming project, part of which involves generating random stars and their parameters.

In order to create a procedurally generated star, I want to randomly select as few parameter values as possible, and then extrapolate the rest using formulas.

For instance by interpreting the Stefan-Boltzmann law I can derive the star's luminosity based on the surface temperature and the star's radius:

$$L = 4 \pi R^2 \sigma T_{e}^4$$

There are however other parameters that I would like to generate, such as the mass of the star. What seems to be able to help me is the mass-luminosity relation:

$$\frac{L}{L_{\odot}} = \left(\frac{M}{M_{\odot}}\right)^a$$

By knowing $a$ (based on my randomly selected mass) it seems that I can derive the star's luminosity. By glancing at the Hertzsprung–Russell diagram (e.g. this one) I can see that I can perhaps somehow calculate the radius of the star, but I'm not entirely sure how.

There is an existing star "generator" which can be found here, however this one interpolates existing data using logarithms.

My full question would be, is there a way to "generate" a "regular", main sequence star, starting from one or two parameters and extrapolating the rest using formulas? Is there a sensible relation between the mass of the star and its radius that can be used to generate a "realistic" star? Or would most parameters need to be interpolated from existing data?

This is a tricky question, not immediate.

If we talk about Main Sequence stars, yes, you can constrain your fictional star by two parameters. The crucial parameters in the diagram, as you said, are the mass and the radius. This is why the HR diagram well represents the stellar population with two axis. Of course, for your scope, we need to do some assumptions. For example, the metallicity, that for your purposes can be fixed as the Solar one. Or, that the initial mass is already in a condition to contract.

You can see it this way: the luminosity is connected with the radius (because it depends on the irradiating surface), while the temperature is connected with the mass (the more is the mass, the more is the pressure at the center of the star).

If you have $L \sim RT$ and $L \sim M$, then you also have $RT \sim M$. The degeneracy from one parameter can be overcame if you have your reference star (the Sun), which allows you to trace isoradii lines on the HR diagram. See here for example: Or, that is equivalent, you can express your first equation (Stefan-Boltzmann), in Solar units as well (as shown here).

Try it out just by your self: choose a mass, or observationally speaking, choose a luminosity. Then trace your line on the HR diagram, and find your star. That star has a defined temperature (spectral class), Mass and Radius as well.

Nice aim, anyway. Have fun!

• Thank you very much for your answer and providing links to interesting resources. In particular, the H-R Diagram Explorer found here is pretty interesting as it nicely shows the relation between the luminosity, temperature and radius of the star. I will continue with my research based on your suggestions, and wait for a bit to see if other people have some other suggestions. – MMM Jul 10 '14 at 9:04
• I have found a webpage claiming that main sequence stars have an average density of 1600 kg/m³, is this an accurate approximation? This would mean I could derive the mass from the radius of the star. – MMM Jul 14 '14 at 19:41
• Ok so I've managed to work out an algorithm that generates stars very close to the HR diagram line by using a density between 1400kg/m³ and 1600kg/m³. What's great is that I simply need to choose a random mass of my star (at the moment it's between 0.5M☉ and 15M☉) and all the formulas work out the rest. Many thanks again for your help. – MMM Jul 15 '14 at 22:24
• @MMM, you are very welcome! Good luck :) – Py-ser Jul 16 '14 at 1:57

Cool aim. I've been intermittently working on a similar program, feel free to use any pieces you like.

It's hosted at: http://thestarsbetween.com/maker/builder?stellar=o&rand=1233

And the code is shared open source at: https://github.com/jaycrossler/procyon

• Thank you very much, I'll have a look and see if there's anything I can use (will give credit too). – MMM Jul 14 '14 at 16:23
• Awesome, let me know if it's useful. I keep wanting to get back to add more to it, so your interest might spark me to add the other features I've been thinking of. – JayCrossler Jul 14 '14 at 18:05