Looking at "Seeing the World Through the Language of Mathematics" with Python... Vol. 7 Kepler's Third Law
Chapter 3: "Don't Be Afraid of Big Numbers"
Book Author: Professor Hirosi Ooguri
This is a Python coding record of Chapter 3, "Don't Be Afraid of Big Numbers" from the book "Seeing the World Through the Language of Mathematics".
This is a mathematical theme related to the "universe".
We will enjoy experiencing the relationship between Kepler's Third Law and logarithms using Python.
Now, let's open the book and set off on a mathematical journey 🚀

Introduction
This blog series introduces the "joy of mathematics" learned from the book "Seeing the World Through the Language of Mathematics" (Gentosha) in the form of "Python coding".
[Citation Notation]
This article cites text and data published in the book listed in the source, and the published text and data have been modified as appropriate.
[Source]
"Seeing the World Through the Language of Mathematics", 3rd printing, Author: Hirosi Ooguri, Gentosha

6. Natural Laws Can Be Seen Through "Logarithms"
Learning Points
Witness the power of a "logarithmic graph" that aligns the planets of the solar system in a straight line.
Import the libraries used in this article.
## インポート
# 数値計算
import pandas as pd
# 可視化
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'Meiryo' # または import japanize_matplotlib
Kepler's Third Law
The professor kindly teaches us "Kepler's Third Law," which Kepler discovered after spending many years.
It is a law that shows the relationship between the "semi-major axis and orbital period of solar system planets" as follows:
The square of a planet's orbital period is proportional to the cube of the semi-major axis of its orbit
1. Taking the positive square root of both sides:
Planet's orbital period = (semi-major axis of orbit)^3/2
2. Taking the common logarithm log10 of both sides:
log10(planet's orbital period) = log10(semi-major axis of orbit)^3/2
3. If you move the exponent on the right side to the front
$${\log_{10} (}$$ planetary orbital period $${)}$$ = $${ \cfrac{3}{2} \log_{10} (}$$ semi-major axis of orbit $${)}$$
The straight line indicated by the formula in 3 seems to have a slope of $${3/2}$$.
Wait? I have to visualize this!

Data for planetary semi-major axes and orbital periods
I thought I needed to prepare data before visualizing, so when I searched online...
Luckily, I found planetary data from the 2007 Chronological Scientific Tables on the Sendai Astronomical Observatory website.
I will quote it here.
Thank you very much!
## p.98 惑星データの設定
# データ引用サイト:仙台市天文台 (理科年表2007年に基づく)
# https://www.sendai-astro.jp/nishikouen/photo/planet/planet_index.html
# データの登録 ※未使用項目はコメントアウトしてます
df = pd.DataFrame({
'惑星名': ['水星', '金星', '地球', '火星', '木星', '土星', '天王星', '海王星'],
# '赤道半径(km)': [2440, 6052, 6378, 3396, 71492, 60268, 25559, 24764],
# '体積(地球=1)': [0.056, 0.857, 1.000, 0.151, 1321.0, 755.0, 63.0, 58.0],
# '密度(g/cm3)': [5.43, 5.24, 5.52, 3.93, 1.33, 0.69, 1.27, 1.64],
'軌道長半径(億km)': [0.579, 1.082, 1.496, 2.279, 7.783, 14.294, 28.75, 45.044],
'公転周期(年)': [0.24, 0.62, 1, 1.88, 11.86, 29.46, 84.02, 164.77],
# '自転周期(日)': [58.65, 243.02, 0.997, 1.026, 0.414, 0.444, 0.718, 0.671],
# '衛星の数': [0, 0, 1, 2, 63, 59, 27, 13],
})
# 軌道長半径を地球=1にして規格化(テキストに合わせる)
df['軌道長半径(地球=1)'] = df['軌道長半径(億km)'] / df.loc[2, '軌道長半径(億km)']
df = df.iloc[:, [0, 1, 3, 2]]
# データフレームの表示
df.round(3)【Execution Result】
The semi-major axis is normalized with Earth = 1.


Finally, visualization
1️⃣ Plotting the data as is
I will visualize the "semi-major axis (Earth=1)" and "orbital period (years)" from the table using their "original scale".
This corresponds to Figure 3-1 on page 98 of the textbook.
## p.98 図3-1 の描画
# 描画領域の設定
plt.figure(figsize=(7, 7))
# 軌道長半径と公園周期の散布図の描画
plt.plot(df['軌道長半径(地球=1)'], df['公転周期(年)'], '--o', lw=1)
# 惑星名の表示
for _, (x, y, s) in df[['軌道長半径(地球=1)', '公転周期(年)', '惑星名']].iterrows():
plt.text(x=x, y=y-5, s=s, ha='left', va='top')
# 修飾
plt.title('惑星の軌道半径と公転周期の関係')
plt.xlabel('軌道長半径 [地球=1]', fontsize=12)
plt.ylabel('公転周期 [年]', fontsize=12)
plt.ylim(-20, 180);【Execution Result】
I got greedy and included up to Neptune!

The overall impression is perhaps a "gentle curve".
Planets close to Earth are clustered together like dumplings.
Uranus and Neptune have such long semi-major axes that they look like they are on a straight line.
2️⃣ Plotting on a logarithmic scale
Next, I will visualize using a common logarithm $${\log_{10}}$$ scale for both the horizontal and vertical axes.
This corresponds to Figure 3-2 on page 98 of the book.
By simply specifying the axis scale as log with base=10 in matplotlib's xscale and yscale, you can draw a logarithmic scale chart without having to convert the data to logarithms.
## p.98 図3-2 の描画
# 描画領域の設定
plt.figure(figsize=(7, 7))
# 軌道長半径と公園周期の散布図の描画
plt.plot(df['軌道長半径(地球=1)'], df['公転周期(年)'], '--o', lw=1)
# 惑星名の表示
for _, (x, y, s) in df[['軌道長半径(地球=1)', '公転周期(年)', '惑星名']].iterrows():
plt.text(x=x*1.03, y=y*0.9, s=s, ha='left', va='top')
# x=1, y=1の垂直線、水平線の描画
plt.axhline(1, color='black', lw=0.5)
plt.axvline(1, color='black', lw=0.5)
# x,y軸を対数log10スケールに変換
plt.xscale('log', base=10)
plt.yscale('log', base=10)
# 修飾
plt.title('惑星の軌道半径と公転周期の関係:対数スケール')
plt.xlabel('log(軌道長半径)', fontsize=12)
plt.ylabel('log(公転周期)', fontsize=12);【Execution Result】
Wow! The planets are lined up in a straight line. And with such nice spacing.
It is a beautiful law of nature!
It is "the straight line of the formula in 3 has a slope of $${3/2}$$"!


Calculating Kepler's Third Law
Let's check with the data to see if the formula in 1 holds true.
Planetary orbital period = semi-major axis of orbit$${^{3/2}}$$
### p.99 惑星の公転周期=起動長半径の3/2乗(p.99のケプラーの第3法則)
df['軌道長半径の3/2乗≒公転周期'] = df['軌道長半径(地球=1)']**(3/2)
df.round(3)【Execution Result】

Let's look at the two columns on the right.
The orbital period and the 3/2 power of the semi-major axis are very close values!
Kepler's Third Law is amazing, isn't it?

The positions of celestial bodies in the solar system on a website
When I searched for a website because I wanted to see how the planets in the solar system move...
I found the "Positions of Celestial Bodies in the Solar System" site by STUDIO KAMADA!
It is a wonderful site where you can specify the date and time to see the positions of celestial bodies in the solar system and enjoy a "moving" celestial simulation!
I stared at it and felt very happy.
Thank you!
Everyone, please experience the simulation for yourself!!!
I will quote a screenshot of the positions of the celestial bodies on a certain day.

The very large numbers of the planets in the solar system were not scary either!
The End
Series Articles
Next Article
Previous Article
Table of Contents
Blog Introduction
I am writing seven series of articles on note.
Please come and take a look!
1. Relaxed Statistics
This is a blog that roughly explores probability and statistics using the Statistics Grade 2 workbook as a guide.
It's okay to treat it like casual conversation. Please come and take a look.
It corresponds to the Statistics Grade 2 Official Workbook CBT version.
Sample code for Python and EXCEL is also available.
2. Experiment! Fun Bayesian Modeling 1 & 2 with PyMC Ver. 5
I will draw and analyze the Bayesian models used in psychological research from the books "Fun Bayesian Modeling" and "Fun Bayesian Modeling 2" using PyMC Ver. 5.
Starting with these books, many Bayesian models are written in R language + Stan.
I will explore the possibilities of PyMC and strive to make Bayesian modeling easy to practice.
Since these are familiar and easy-to-visualize themes, please run them with PyMC and let's enjoy them together!
3. Experiment! Iwanami Data Science 1 Bayesian Modeling with PyMC Ver. 5
I will draw and analyze the Bayesian models by four Bayesians from the book "Experiment! Iwanami Data Science Vol. 1" using PyMC Ver. 5.
This book is a good resource for learning the basics of Bayesian programming.
I feel like I've become friends with Bayesian methods by happily running PyMC models.
Everyone, please run them with PyMC and let's play and learn together!
4. Fun Copying: Bayesian, Python, etc.
I will blog about the results of my 'book transcription activities' involving Bayes, Python, and others.
I am mainly working on translations into Python.
I hope this serves as sample code for fellow learners who are also transcribing code.🍀
5. Introduction to Time Series Analysis for Psychology with R and Stan, using Python and PyMC Ver. 5
I will implement the time series analysis from the book 'Introduction to Time Series Analysis for Psychology with R and Stan' using Python and PyMC Ver. 5.
This book is packed with themes on time series analysis!
I truly realized the depth of time series analysis.
I will enjoy learning time series analysis with my favorite language, Python.
6. Writing about Data Science-like things
I write columns on statistics, data analysis, AI, machine learning, and Python on an irregular basis.
There are many articles related to statistics and data science books.
Series on 'Statistics,' 'Python,' 'Mathematics and Python,' and 'R' have been created.
7. Python Machine Learning Programming Practice Log
I wrote articles about my various thoughts while studying the book 'Python Machine Learning Programming: PyTorch & scikit-learn Edition'.
This book is a textbook for scikit-learn and PyTorch.
Please feel free to give it a try if you like.
Thank you very much for reading until the end.
いいなと思ったら応援しよう!
応援ありがとうございます。これからもがんばって記事を作成します!