RSS

タグ別アーカイブ: SpecialFunctions

Julia の勉強:特殊関数

特殊関数は SpecialFunctions パッケージをインストールすることで利用できます。

pkg> add SpecialFunctions

このパッケージに含まれる特殊関数は

です。

ガンマ関数

ガンマ関数は階乗 n! を複素数に拡張した関数です。SpecialFunctions では派生型の関数がいくつかサポートされていますが、基本の gamma() 関数を試してみました。

変数は複素数が可能ですが、グラフにしやすい正の実数変数で計算してみました。

# ガンマ関数
using SpecialFunctions
using Plots

xs = Float64[]
ys = Float64[]

for x = range(0.04, 6, step=0.001)
    try
        y = gamma(x)
        #@show x, y
        append!(xs, x)
        append!(ys, y)
    catch
        println("Error on ", x)
    end
end

println("Plot start ..")
plot(xs, ys, show=true, framestyle=:origin, w=2)

print("> ")
read(stdin, Char)

指数積分および三角積分

指数積分は指数関数を含む関数の積分、三角積分は正弦や余弦を含む関数の積分ですが、これらは初等関数の組み合わせで表すことができずに特殊関数となります。

下のプログラムは指数積分関数のサンプルです。

# 指数積分関数 Ei(z)
using SpecialFunctions
using Plots

println("Start plot ..")
plot(range(-5, 5, step=0.1), expinti, show=true, framestyle=:origin, w=2)

print("> ")
read(stdin, Char)

誤差関数

誤差関数は確率論、統計などに使われる特殊関数です。誤差関数にはいくつかのバラエティがありますが、下のプログラムは基本的な誤差関数 erf() です。

# 誤差関数
using SpecialFunctions
using Plots

println("Start plot ..")
plot(range(-3, 3, step=0.01), erf, show=true, framestyle=:origin)

print("> ")
read(stdin, Char)

エアリー 関数

エアリー関数はイギリスの天文学者エアリーにちなんで名づけられた関数で、エアリーの微分方程式の解になります。

# エアリー関数
using SpecialFunctions
using Plots

println("Start plot ..")
plot(range(-15.0, 5.0, step=0.01), airyai, show=true, framestyle=:origin, w=2)

print("> ")
read(stdin, Char)

ベッセル関数

ベッセル関数は電磁気学などでよく使われる特殊関数で変種がたくさんあります。ここでは 0 と 1 次第一種ベッセル関数を使ってみます。

# ベッセル関数 J0(x)
using SpecialFunctions
using Plots

println("Start plot ..")
plot(range(-20.0, 20.0, step=0.02), [besselj0, besselj1], show=true, framestyle=:origin, w=2)

print("> ")
read(stdin, Char)

楕円積分

振り子運動などに関係する特殊関数です。ある関数を積分した時に得られる関数です。

# 楕円積分
using SpecialFunctions
using Plots

println("Start plot ..")
plot(range(-5.0, 0.9, step=0.01), ellipk, show=true, framestyle=:origin, w=2)

print("> ")
read(stdin, Char)

ゼータ関数

数論や力学で使用される関数でいくつもの変種がありますが、一番歴史のあるのはリーマンゼータ関数だそうです。

ここでは、そのリーマンゼータ関数を使用してみます。

# リーマンゼータ関数
using SpecialFunctions
using Plots

println("Start plot ..")
plot(range(-1.0, 4.0, step=0.01), zeta, show=true, framestyle=:origin, w=2)

print("> ")
read(stdin, Char)
 
コメントする

投稿者: : 2021/12/23 投稿先 Julia

 

タグ: ,