Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
121 views
ubuntu2404
Kernel: Julia 1.11

Modern Thermodynamics with Julia in CoCalc

Part 1: Stellar Thermodynamics and Astrophysics

This notebook contains Part 1 from the main Modern Thermodynamics with Julia in CoCalc notebook.

For the complete course, please refer to the main notebook: Modern Thermodynamics with Julia in CoCalc

import Pkg; Pkg.add("PlotThemes") using Plots, Printf, Statistics, LinearAlgebra using PlotThemes theme(:bright) # Fundamental constants (2018 CODATA values) const k_B = 1.380649e-23 # Boltzmann constant (J/K) const N_A = 6.02214076e23 # Avogadro's number (1/mol) const R = k_B * N_A # Universal gas constant (J/mol·K) const σ_SB = 5.670374419e-8 # Stefan-Boltzmann constant (W/m²·K⁴) const c = 299792458.0 # Speed of light (m/s) const h = 6.62607015e-34 # Planck constant (J·s) const G = 6.67430e-11 # Gravitational constant (m³/kg⋅s²) const M_sun = 1.989e30 # Solar mass (kg) println("🌟 MODERN THERMODYNAMICS: STELLAR ASTROPHYSICS") println(repeat("=", 55)) println("Exploring thermodynamics in stars and black holes") println() println("Universal Constants:") println("• Boltzmann constant: k_B = $(k_B) J/K") println("• Stefan-Boltzmann: σ = $(σ_SB) W/(m²·K⁴)") println("• Gravitational constant: G = $(G) m³/(kg⋅s²)") println("• Solar mass: M☉ = $(M_sun) kg")

Stellar Thermodynamics and Astrophysics

Stars as Thermodynamic Systems

Stars are massive thermodynamic systems governed by:

  • Hydrostatic equilibrium: Pressure gradient balances gravitational force

  • Energy transport: Radiation and convection carry energy outward

  • Nuclear fusion: Converts mass to energy in stellar cores

  • Stellar evolution: Thermodynamic properties change over stellar lifetime

Key Stellar Relations

Stefan-Boltzmann Law for stellar luminosity: L=4πR2σTeff4L = 4\pi R^2 \sigma T_{eff}^4

where LL is luminosity, RR is stellar radius, and TeffT_{eff} is effective temperature.

Hydrostatic Equilibrium: dPdr=ρGM(r)r2\frac{dP}{dr} = -\frac{\rho GM(r)}{r^2}

Virial Theorem for gravitational systems: 2K+U=02K + U = 0

where KK is kinetic energy and UU is gravitational potential energy.

Black Hole Thermodynamics

Hawking Temperature: TH=c38πGMkBT_H = \frac{\hbar c^3}{8\pi G M k_B}

Bekenstein-Hawking Entropy: SBH=Ac34GS_{BH} = \frac{A c^3}{4G\hbar}

where A=4πrs2A = 4\pi r_s^2 is the event horizon area and rs=2GM/c2r_s = 2GM/c^2 is the Schwarzschild radius.

# Stellar physics functions function stellar_luminosity(R, T_eff) """Stefan-Boltzmann law: L = 4πR²σT⁴""" return 4π * R^2 * σ_SB * T_eff^4 end function main_sequence_lifetime(M) """Rough main sequence lifetime: τ ∝ M/L ∝ M^(-2.5) (very approximate)""" # For solar-type stars, lifetime scales as (M/M_sun)^(-2.5) τ_sun = 10e9 * 365.25 * 24 * 3600 # 10 billion years in seconds return τ_sun * (M / M_sun)^(-2.5) end function hawking_temperature(M) """Hawking temperature: T_H = ℏc³/(8πGMk_B)""" = h / (2π) return ( * c^3) / (8π * G * M * k_B) end function schwarzschild_radius(M) """Schwarzschild radius: r_s = 2GM/c²""" return 2 * G * M / c^2 end function bekenstein_hawking_entropy(M) """Bekenstein-Hawking entropy: S = Ac³/(4Gℏ)""" = h / (2π) r_s = schwarzschild_radius(M) A = 4π * r_s^2 # Event horizon area return A * c^3 / (4 * G * ) end println("=== STELLAR THERMODYNAMICS ===") println("Main Sequence Stars (Hydrostatic Equilibrium):") println() # Main sequence stars data stellar_data = [ ("Red dwarf (M-type)", 0.1, 0.1, 3000), ("Sun (G-type)", 1.0, 1.0, 5778), ("Blue giant (B-type)", 10.0, 5.0, 20000), ("Blue supergiant (O-type)", 50.0, 20.0, 40000) ] println("Main Sequence Properties:") println(repeat("-", 80)) @printf "%-25s %8s %8s %10s %12s %12s\n" "Star Type" "M/M☉" "R/R☉" "T_eff (K)" "L/L☉" "Lifetime (yr)" println(repeat("-", 80)) for (star_name, M_ratio, R_ratio, T_eff) in stellar_data M_star = M_ratio * M_sun R_star = R_ratio * 6.96e8 # Solar radius in meters L_star = stellar_luminosity(R_star, T_eff) L_sun = stellar_luminosity(6.96e8, 5778) # Solar luminosity L_ratio = L_star / L_sun lifetime = main_sequence_lifetime(M_star) lifetime_years = lifetime / (365.25 * 24 * 3600) @printf "%-25s %8.1f %8.1f %10.0f %12.1f %12.2e\n" star_name M_ratio R_ratio T_eff L_ratio lifetime_years end println() println("Stellar Evolution Insights:") println("• More massive stars are hotter, brighter, but shorter-lived") println("• Luminosity scales roughly as M³⁻⁴ (mass-luminosity relation)") println("• Lifetime scales as M/L ∝ M⁻²·⁵ (more massive = faster burning)") println("• Red dwarfs will outlive the universe's current age") println("• Massive stars explode as supernovae after millions of years") println()
using Printf println("=== BLACK HOLE THERMODYNAMICS ===") println("Hawking Radiation and Event Horizon Physics") println() black_holes = [ ("Stellar-mass BH", 10.0), ("Intermediate BH", 1000.0), ("Sagittarius A*", 4e6), ("M87* (imaged BH)", 6.5e9), ("Galaxy cluster BH", 1e10) ] println("Black Hole Thermodynamic Properties:") println(repeat("-", 90)) @printf "%-20s %12s %12s %15s %15s\n" "Black Hole Type" "Mass (M☉)" "r_s (km)" "T_Hawking (K)" "Entropy (J/K)" println(repeat("-", 90)) for (bh_name, M_bh_solar) in black_holes M_bh = M_bh_solar * M_sun r_s = schwarzschild_radius(M_bh) T_hawk = hawking_temperature(M_bh) S_bh = bekenstein_hawking_entropy(M_bh) @printf "%-20s %12.1e %12.1f %15.2e %15.2e\n" bh_name M_bh_solar (r_s/1000) T_hawk S_bh end println() println("Black Hole Thermodynamic Insights:") println("• Larger black holes are colder (T ∝ 1/M)") println("• Entropy scales with area, not volume (S ∝ M²)") println("• Stellar-mass BHs evaporate faster than universe age") println("• Supermassive BHs will outlive all stars") println("• Information paradox: where does information go?") println("• Holographic principle: 3D information stored on 2D surface") println() println("Black Hole Evaporation:") M_stellar = 10 * M_sun τ_evap_years = 2e67 * (M_stellar / M_sun)^3 universe_age = 1.38e10 @printf "• Stellar-mass BH (10 M☉) evaporation time: ~%.1e years\n" τ_evap_years @printf "• Universe current age: %.1e years\n" universe_age @printf "• Ratio: %.1e times longer than universe age\n" (τ_evap_years / universe_age) println("• Black holes are effectively eternal on cosmic timescales!") println()

From Cosmic Furnaces to Molecular Machines

We've explored the thermodynamics of the cosmos—from the nuclear fusion powering stars to the enigmatic physics of black holes. Through the lens of stellar evolution and Hawking radiation, we've seen how thermodynamic principles govern the largest structures in our universe.

Our journey revealed that stars are massive heat engines, converting gravitational potential energy and nuclear binding energy into the light that illuminates the cosmos. The Stefan-Boltzmann law elegantly connects a star's temperature to its luminosity, while the remarkable discovery of black hole thermodynamics shows that even event horizons obey the laws of entropy.

But how do these universal principles manifest in the realm of life?

While stars operate at temperatures of millions of degrees, life thrives in a narrow temperature range. Yet the same fundamental laws govern both domains. The entropy that increases as stars burn their nuclear fuel also drives the molecular processes within every living cell.

Journey from Stars to Life

The energy that powers life on Earth ultimately comes from our star, the Sun. Through the remarkable process of photosynthesis, organisms have evolved to capture stellar energy and convert it into the chemical bonds that fuel the biosphere.

In Part 2, we'll explore how thermodynamics governs biological systems—from ATP synthesis to metabolic scaling laws. You'll discover how life maintains order against the tide of entropy, how organisms optimize energy conversion, and why size matters in the biological world.

Continue to Part 2: Biological Thermodynamics and Life →

or

Read the Complete Series