GSL::Function.new
GSL::Function.alloc
Constructor for an instance of the Function
class.
ex)
require 'gsl' include GSL f = GSL::Function.new { |x| sin(x) }
The value of the function is evaluated by the method eval
, as
p f.eval(x)
The function can have constant parameters of arbitrary numbers. Here is an
example in case of exponential function f(x; a, b) = a*exp(-b*x)
.
f = Function.new { |x, params| # x: a scalar, params: an array a = params[0] b = params[1] a*exp(-b*x) }
To evaluate the function f(x) = 2*exp(-3*x)
,
f.set_params(2, 3) f.eval(x)
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| ... }
GSL::Function#set(proc, params)
This method sets or resets the procedure of self, 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)
GSL::Function#set_params(params)