File: function.rdoc [gsl-1.15.3 Documentation]

### Home Classes Methods

### Files

- alf.rdoc
- blas.rdoc
- bspline.rdoc
- changes.rdoc
- cheb.rdoc
- cholesky_complex.rdoc
- combi.rdoc
- complex.rdoc
- const.rdoc
- dht.rdoc
- diff.rdoc
- ehandling.rdoc
- eigen.rdoc
- fft.rdoc
- fit.rdoc
- function.rdoc
- graph.rdoc
- hist.rdoc
- hist2d.rdoc
- hist3d.rdoc
- index.rdoc
- integration.rdoc
- interp.rdoc
- intro.rdoc
- linalg.rdoc
- linalg_complex.rdoc
- math.rdoc
- matrix.rdoc
- min.rdoc
- monte.rdoc
- multimin.rdoc
- multiroot.rdoc
- narray.rdoc
- ndlinear.rdoc
- nonlinearfit.rdoc
- ntuple.rdoc
- odeiv.rdoc
- perm.rdoc
- poly.rdoc
- qrng.rdoc
- randist.rdoc
- ref.rdoc
- rng.rdoc
- rngextra.rdoc
- roots.rdoc
- screenshot.rdoc
- sf.rdoc
- siman.rdoc
- sort.rdoc
- start.rdoc
- stats.rdoc
- sum.rdoc
- tensor.rdoc
- tut.rdoc
- use.rdoc
- vector.rdoc
- vector_complex.rdoc
- wavelet.rdoc

### Class Index

Quicksearch

No matching classes.

# GSL::Function class

## Class Methods

- GSL::Function.alloc

  Constructor.

  - ex:

        require("gsl")
        f = GSL::Function.alloc { |x| sin(x) }

  The value of the function is calculated by the method `Function#eval`, as

      p f.eval(x)

  The function can have parameters of arbitrary numbers. Here is an example in case of exponential function `f(x; a, b) = a*exp(-b*x)`.

      f = GSL::Function.alloc { |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)

## Methods

- GSL::Function#eval(x)

- GSL::Function#call(x)

- GSL::Function#at(x)

- GSL::Function#

  These methods return a value of the function at `x`.

      p f.eval(2.5)
      p f.call(2.5)
      p f[2.5]

  The argument `x` can be a scalar, a Vector, Matrix, Array or Range.

- GSL::Function#set { |x| ... }

- GSL::Function#set(proc, params)

  This method sets or resets the procedure of `self`, as

      f = GSL::Function.alloc { |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)

  This set the constant parameters of the function.

## Graph

- GSL::Function#graph(x[, options])

  This method uses `GNU graph` to plot the function `self`. The argument `x` is given by a `GSL::Vector` or an `Array`.

  Ex: Plot sin(x)

      f = Function.alloc { |x| Math::sin(x) }
      x = Vector.linspace(0, 2*M_PI, 50)
      f.graph(x, "-T X -g 3 -C -L 'sin(x)'")

## Example

A quadratic function, f(x) = x^2 + 2x + 3.

    >> require("gsl")
    => true
    >> f = Function.alloc { |x, param| x*x + param[0]*x + param[1] }
    => #<GSL::Function:0x6e8eb0>
    >> f.set_params(2, 3)
    => #<GSL::Function:0x6e8eb0>
    >> f.eval(2)                             <--- Scalar
    => 11
    >> f.eval(1..4)                          <--- Range
    => [6.0, 11.0, 18.0, 27.0]
    >> f.eval([1, 2, 3])                     <--- Array
    => [6.0, 11.0, 18.0]
    >> f.eval(Matrix.alloc([1, 2], [3, 4]))    <--- GSL::Matrix
    [ 6.000e+00 1.100e+01
      1.800e+01 2.700e+01 ]
    => #<GSL::Matrix:0x6dd1b4>

back

[Validate]

Generated with the Darkfish Rdoc Generator 2.