Last active
April 19, 2018 06:31
-
-
Save komasaru/6f59466c21037557342ff0ffb2f9b055 to your computer and use it in GitHub Desktop.
Ruby script to calculate Schwarzschild radius.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/ruby | |
# coding: utf-8 | |
#--------------------------------------------------------------------------------- | |
#= シュバルツシルト半径(Schwarzschild radius) の計算 | |
# : JPL DE430 の惑星質量データを利用して、太陽・惑星・月のシュバルツシルト半径を求める。 | |
# | |
# * JPL データ : ftp://ssd.jpl.nasa.gov/pub/eph/planets/ascii/de430/header.430_572 | |
# * 万有引力定数: http://physics.nist.gov/cgi-bin/cuu/Value?bg | |
# * シュバルツシルト半径 r = 2 * G * M / c^2 | |
# | |
# date name version | |
# 2016.07.18 mk-mode.com 1.00 新規作成 | |
# | |
# Copyright(C) 2016 mk-mode.com All Rights Reserved. | |
#--------------------------------------------------------------------------------- | |
#++ | |
class CalcSchwarzschildRadius | |
MASS = { | |
" 太陽" => 1.988475e+30, | |
" 水星" => 3.301096e+23, | |
" 金星" => 4.867466e+24, | |
" 地球" => 5.972365e+24, | |
" 月" => 7.346031e+22, | |
" 火星" => 6.417120e+23, | |
" 木星" => 1.898580e+27, | |
" 土星" => 5.684766e+26, | |
"天王星" => 8.682168e+25, | |
"海王星" => 1.024340e+26, | |
"冥王星" => 1.463872e+22 | |
} # 天体の質量 (単位: kg) | |
C = 299792458.0 # 光の速度 (単位: m/s) | |
G = 6.67408e-11 # 万有引力定数 (単位: m^3 kg^-1 s^-2) | |
def calc | |
puts "[シュバルツシルト半径]" | |
MASS.each do |k, m| | |
printf(" %s: %13.8f m\n", k, 2 * G * m / (C * C)) | |
end | |
rescue => e | |
msg = "[#{e.class}] #{e.message}\n" | |
msg << e.backtrace.each { |tr| "\t#{tr}"}.join("\n") | |
$stderr.puts msg | |
exit 1 | |
end | |
end | |
CalcSchwarzschildRadius.new.calc if __FILE__ == $0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment