複素変数Bessel関数の c 言語ライブラリ

身の回りの cコンパイラでも c90, c99 の実装が少しづつ進んできて、 便利になりましたが、GSL(GNU Scientific Library) などでも Bessel 関数は実変数のみで、 複素変数の Bessel 関数になると、自作せざるを得ません。

プログラミングの方法としては、

を組み合わせることになりますが、 級数展開と漸近展開については Bessl 関数の本とか、 数学公式集を見てください。(注1)

多項式近似については

  M.Abramowitz and I.E.Stegun,-
	Handbook of Mathematical Functions
	(U.S.Department of Commerce)
が素晴らしい本ですが、今は
   Milton Abramowitz, Irene A. Stegun,-
	Handbook of Mathematical Functions: with Formulas, Graphs,
	and Mathematical Tables
		(Dover Books on Mathematics)
等から入手できますので、お持ちでないかたは1冊お求めになることをお勧めします。

また、数学公式集に関しては、日本ではあまり知られていないようですが、

  Murry R.Spiegel,- MATHEMATICAL HANDBOOK
	(McGraw-Hill) Schaum's Outlines series
が非常に使いやすいです。 いずれも amazon.co.jp で容易に入手できます。

一方、複素数対応が遅れた c でなく 歴史の長い Fortran ですと、 Netlib の Fortran のライブラリ

http://netlib.org/amos/

が古くから使われていて、 ここでは、この Fortran プログラムを c から使えるようにしてみます。 (注2)

方針としては、上記の URL から

  cbesh.f plus dependencies - Bessel function of third kind (Hankel Function)
  cbesi.f plus dependencies - Modified Bessel function of first kind
  cbesj.f plus dependencies - Bessel function of first kind
  cbesk.f plus dependencies - Modified Bessel function of second kind
  cbesy.f plus dependencies - Bessel function of second kind
  cairy.f plus dependencies - Airy Function Ai(z)
  cbiry.f plus dependencies - Airy Function Bi(z)
と関連ファイルを取得して、Fortran ライブラリを作成し、 下記の wrapper 関数と prototype を Complex.h ファイルにまとめることにしました。

Cbes.h に含まれるライブラリ関数は次のとおりです。

ライブラリ関数
-- Bessel Functions --
Jn(n,z)    Bessel function of the first kind and integer order n.
Yn(n,z)    Bessel function of the second kind and integer order n.
In(n,z)    Modified Bessel function of the first kind and integer order n.
Kn(n,z)    Modified Bessel function of the second kind and integer order n.
H1(n,z)    Hankel function of the first kind and integer order n.
H2(n,z)    Hankel function of the second kind and integer order n.
-- Derivatives of Bessel Functions --
Jnd(n,z)   derivative of the Bessel function of the first kind and integer order n.
Ynd(n,z)   derivative of the Bessel function of the second kind and integer order n.
Ind(n,z)   derivative of the modified Bessel function of the first kind and integer order n.
Kd(n,z)    derivative of the modified Bessel function of the second kind and integer order n.
H1d(n,z)   derivative of the Hankel function of the first kind and integer order n.
H2d(n,z)   derivative of the Hankel function of the second kind and integer order n.
-- Airy Functions --
Ai(z)      Airy function of the first kind.
Bi(z)      Airy function of the second kind.
-- Derivatives of Airy Functions --
Aid(z)     First derivative of the Airy function of the first kind.
Bid(z)     First derivative of the Airy function of the first kind.

複素変数Bessel関数の c 言語ライブラリ - ソースコード

ライブラリとサンプルプログラムを展開するディレクトリに cbes.tar.gz をおいて

  tar zxvf cbes.tar.gz
  make
を実行するとライブラリ cbes.a とテストプログラム kelvin ができます。

アプリケーションプログラムではテストプログラム kelvin.c のように

 1) Cbes.h を include する
 2) コンパイル時には

        -L./ -L/usr/local/lib/gcc46 -lgfortran -lm      # FreeBSD-8.4 のとき
        -L./ -L/usr/local/lib/gcc48 -lgfortran -lm      # FreeBSD-10.3 のとき

    のように gfortran の library への path を指定して、static link
してください。

動作確認は FreeBSD-8.4 (gcc 4.2.1 + gfortran 4.6.3) と FreeBSD-10.3 (clang 3.4.1 + gfortran 4.8.5) で行っています。Fortran コンパイラのライブラリ の置き場所は上記のように OS とバージョンに依存しますので、 makefile の library path (-L) は利用環境に合わせて書き換えてください。

テストプログラム (kelvin.c) では

  H.B.Dwight,- TABLES OF INTEGRALS AND OTHER MATHEMATICAL DATA
	(MACMILLAN PUBLISHING CO.,INC.)
の Table 1050 の数表 bern(x), bein(x), kern(x), kein(x) 関数とその微分を作っています。 この本も私の好きな本の一つで、今でも amazon.com から入手できるようです。

注1 - Bessel 関数の本

Bessel関数は理工学の広範な分野で重要な役割を果たしますので、 古くから文献も非常に多いのですが、私が楽しく読めたものをあげておきます。

  N.W.McLachlan,- Bessel Functions for engineers
        (Oxford Engineering Science Series), 1955

  Frank Bowman,- Introduction to Bessel Function
        (Dover Publications Inc.), 1958 ISBN 0-486-60462-4

  Dover には良い本が多いのですが、これは和訳もあります。

  フランク・ボウマン,- ベッセル関数入門
        (日新出版) ISBN4--8173-0033-7
これらのいずれにも代表的な工学的応用例が収録されていますが、 書かれた時代が現代のSI単位系ではなく、 Gauss単位系であることに注意してください。

公式集はたくさんありますが、何故か日本ではあまり知られていない

  MURRAY R. SPIEGEL,- MATHEMATICAL HANDBOOK
	(MacGraw-Hill)
が実に使いやすいです。Schaum's Outlines のシリーズには非常に良い本があります。

また、電気工学者による

  HERBERT BRISTOL DWIGHT,- TABLES OF INTEGRALS AND OTHER MATHEMATICAL DATA
	(MACMILLAN PUBLISHING CO., INC)
も今でも入手可能で、これも好きです。歴史のある本なので、アメリカでは、 母親が使ったものを譲り受けて使っているといった人も居るようです。

もっと、深く勉強したいという人には、今でも入手できる

  G.N.Watson,- A Treatise of the Theory of Bessel Functions
	(Merchant Books) 1-60386-104-1
でしょうか。ほぼ1世紀前の復刻(デジタル)版ですが、非常に綺麗で読みやすいです。

注2 - c++ 用複素変数 Bessel関数ライブラリ

http://netlib.org/amosc++ から使えるようにしたものは、 Complex_Bessel として公開されています。

平林 浩一, 2016,2018