GSL_Function class

GSL では、数値積分や方程式の根を探す関数は、被積分関数や解くべき方程式などを gsl_function 型で定義して与えるようになっている。Ruby/GSL では、 GSL_Function という Proc ライクなクラスを定義し、数値積分や根探索はそれらの メソッドとして提供する。gsl_function 型の制約により、GSL_Function クラスには 1変数関数のみ定義できる。

Class Methods

GSL_Function.new
GSL_Function.alloc

This creates a GSL_Function object with a procedure block. For example, an object corresponding to the function sin(x) is given by

f = GSL_Function.new { |x| sin(x) }

One can compute sin(x) with the object f and the method eval, as

p f.eval(x)

Methods

GSL_Function#eval(x)
GSL_Function#call(x)
GSL_Function#[x]

These methods return a value of the function at x.

p f.eval(2.5)
p f.call(2.5)
p f[2.5]
GSL_Function#set { |x| ... }

This method sets the procedure of the GSL_Function object, as

f = GSL_Function.new { |x| sin(x) }
p f.eval(1.0)               <- sin(1.0)
f.set { |x| cos(x) }
p f.eval(1.0)               <- cos(1.0)