1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Juliaでガンマ関数とベッセル関数を使う

Posted at

概要

昔調べた時に結構詰まったので備忘録がわりに書いておきます。

やり方

juliaはccallでmath.hの関数を呼び出せるのでそれを使うだけです
#ガンマ関数
function gamma(x::T) where T
    result = ccall(:gamma,Cdouble,(Cdouble,),x)
    t < typemax(T) ? T(t) : t #引数が整数の場合ガンマ関数は整数を返す方が望ましいため変換 ただしInf行くこともあるのでtypemaxを通しました
end
#第1種ベッセル関数
function jn(n::Integer,x::Real)
    ccall(:jn,Cdouble,(Cint,Cdouble),n,x)
end
#第2種ベッセル関数
function yn(n::Integer,x::Real)
    ccall(:yn,Cdouble,(Cint,Cdouble),n,x)
end

参考文献

math.hの関数

IBM document ベッセル関数
IBM document ガンマ関数
上のIBM documentを探してみると意外な関数が見つかるかも。
ccall周り
Juliaの公式ドキュメント(英語)

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?