Skip to content

Instantly share code, notes, and snippets.

View komasaru's full-sized avatar

mk-mode komasaru

View GitHub Profile
@komasaru
komasaru / interpolate_lagrange.rb
Last active April 19, 2018 04:52
Ruby script to interpolate with Lagrange method.
#! /usr/local/bin/ruby
#*********************************************
# ラグランジュ補間
#*********************************************
#
class InterpolateLagrange
# あらかじめ与える点
X = [0.0, 2.0, 3.0, 5.0, 8.0]
Y = [0.8, 3.2, 2.8, 4.5, 1.9]
@komasaru
komasaru / nonlinear_equation_newtown.rb
Created February 21, 2013 08:35
Ruby script to calc nonlinear equation by newtown method.
# -*- coding: utf-8 -*-
#*********************************************
# 非線形方程式の解法 ( ニュートン法 )
#*********************************************
class NonlinearEquationNewton
# 各種定数
EPS = 1e-08 # 打ち切り精度
LIMIT = 50 # 打ち切り回数
# 計算クラス
@komasaru
komasaru / nonlinear_equation.rb
Created February 21, 2013 08:38
Ruby script to calc nonlinear equation by bisection method.
# -*- coding: utf-8 -*-
#*********************************************
# 非線形方程式の解法 ( 2分法 )
#*********************************************
class NonlinearEquation
# 各種定数
EPS = 1e-08 # 打ち切り精度
LIMIT = 50 # 打ち切り回数
# 計算クラス
@komasaru
komasaru / taylor_expansion_cos.rb
Created February 21, 2013 08:40
Ruby script to calc taylor expansion of cos.
# -*- coding: utf-8 -*-
#*********************************************
# テイラー展開 [ cos(x) ]
#*********************************************
class TaylorExpansionCos
# 各種定数
EPS = 1e-08 # 精度
PI = 3.1415926535 # 円周率
# 計算クラス
@komasaru
komasaru / taylor_expansion.rb
Created February 21, 2013 08:41
Ruby script to calc taylor expansion of exp(x).
# -*- coding: utf-8 -*-
#*********************************************
# テイラー展開 [ exp(x) ]
#*********************************************
class TaylorExpansion
# 各種定数
EPS = 1e-08 # 精度
# 計算クラス
class Calc
@komasaru
komasaru / definite_integral_simpson.rb
Created February 21, 2013 08:42
Ruby script to definite integral by simpson method.
# -*- coding: utf-8 -*-
#*********************************************
# シンプソン則による定積分
#*********************************************
class DefiniteIntegralSimpson
# 積分区間分割数
M = 100
# 計算クラス
class Calc
@komasaru
komasaru / definite_integral_trapzoid.rb
Created February 21, 2013 08:43
Ruby script to definite integral by trapzoid method.
# -*- coding: utf-8 -*-
#*********************************************
# 台形則による定積分
#*********************************************
class DefiniteIntegralTrapzoid
# 積分区間分割数
M = 100
# 計算クラス
class Calc
@komasaru
komasaru / rndnum_box_muller.rb
Created February 21, 2013 08:45
Ruby script to calc normal random numbers by box-muller method.
#*********************************************
# ボックス=ミューラー法法による正規乱数生成
#*********************************************
class RndnumBoxMuller
# 各種定数
M = 10 # 平均
S = 2.5 # 標準偏差
N = 10000 # 発生させる乱数の個数
PI = 3.1415926535 # 円周率
SCALE = N / 100.0 # ヒストグラム用スケール
@komasaru
komasaru / chi2_rndnum.rb
Last active December 14, 2015 00:59
Ruby script to calc uniform random numbers by chi-squared distribution method.
# -*- coding: utf-8 -*-
class Chi2Rndnum
# 各種定数定義
A = 1103515245 # 乗数
C = 12345 # 加数
M = 2 ** 31 # 法
N = 1000 # 発生させる乱数の個数
M_MAX = 10 # 整数乱数の範囲
F = N / M_MAX.to_f # 期待値
S = 40.0 / F # ヒストグラム用スケール
@komasaru
komasaru / rndnum_lcgs.rb
Created February 21, 2013 08:49
Ruby script to calc uniform random numbers by LCGs method.
# -*- coding: utf-8 -*-
class RndnumLcgs
# 各種定数定義
A = 1103515245 # 乗数
C = 12345 # 加数
M = 2 ** 31 # 法
N = 1000 # 発生させる乱数の個数
# 計算クラス
class Calc