# module NumRu::Derivative in derivative.rb

## todo

- decide argument of b_expand_linear_ext is Symbol or Numeric.
  - now is Numeric.
  - it denpends the treatment of dRuby.
- support other boundary conditions.

## Index

- module NumRu::Derivative
  - threepoint_O2nd_deriv
    - First derivative (2nd Order difference use three point.)
  - cderiv
    - First derivative (center difference use two point.)
  - b_expand_linear_ext
    - return array extended boundaries with linear extention.
  - cdiff
    - return difference. (center difference)

# module NumRu::Derivative

Module functions of Derivative Operater for NArray.

`threepoint_O2nd_deriv(z, x, dim, bc=LINEAR_EXT)`

  Derivate `z` respect to `dim` th dimension with 2nd Order difference. return an NArray which result of the difference z divided difference `x` (in other wards,

      (s**2*z_{i+1} + (t**2 - s**2)*f_{i} - t**2*f_{i-1}) / (s*t*(s + t)):
      now s represents (x_{i} - x_{i-1}) ,t represents (x_{i+1} - x_{i})
      and _{i} represents the suffix of {i} th element in the ((<dim>)) th
      dimension of array. ).

  ARGUMENTS

  - z (NArray): a NArray which you want to derivative.
  - x (NArray): a NArray represents the dimension which derivative respect to. z.rank must be 1.
  - dim (Numeric): a Numeric represents the dimention which derivative respect to. you can give number count backward (dim<0), but z.rank ¡Üdim must be > 0.
  - bc (Numeric) : a Numeric which represent boundary condition. now only LINEAR_EXT(=1) supported. LINEAR_EXT load b_expand_linear_ext which extend boundary with lenear value.

  RETURN VALUE

  - O2nd_deriv_data (NArray): (s**2*z_{i+1} + (t**2 - s**2)*f_{i} - t**2*f_{i-1}) / (s*t*(s + t))
`cderiv(z, x, dim, bc=LINEAR_EXT)`

  Derivate `z` respect to `dim` th dimension with center difference. return an NArray which result of the difference z divided difference `x` ( in other wards, (z_{i+1} - z_{i-1}) / (x_{i+1} - x_{i-1}): now _{i} represents the suffix of {i} th element in the dim th dimension of array. ).

  ARGUMENTS

  - z (NArray): a NArray which you want to derivative.
  - x (NArray): a NArray represents the dimension which derivative respect to. z.rank must be 1.
  - dim (Numeric): a Numeric represents the dimention which derivative respect to. you can give number count backward (dim<0), but z.rank ¡Üdim must be > 0.
  - bc (Numeric) : a Numeric which represent boundary condition. now only LINEAR_EXT(=1) supported. LINEAR_EXT load b_expand_linear_ext which extend boundary with lenear value.

  RETURN VALUE

  - cderiv_data (NArray): (z_{i+1} - z_{i-1}) / (x_{i+1} - x_{i-1})
`b_expand_linear_ext(z, dim)`

  expand boundary with linear value. extend array with 1 grid at each boundary with dim th dimension, and assign th value which diffrential value between a grid short of boundary and boundary grid in original array. (on other wards, 2*z_{0}-z_{1} or 2*z_{n-1}-z_{n-2}: now _{i} represents the

      suffix of {i} th element in the ((<dim>)) th dimension of array. ).

  ARGUMENTS

  - z (NArray): a NArray which you want to expand boundary.
  - dim (Numeric): a Numeric represents the dimention which derivative respect to. you can give number count backward (dim<0), but z.rank ¡Üdim must be > 0.

  RETURN VALUE

  - expand_data (NArray):
`cdiff(x, dim)`

  Diffrence operater. return an NArray which a difference x ( in other wards, (x_{i+1} - x_{i-1}): now _{i} represents the suffix of {i} th element in the dim th dimension of array. ).

  ARGUMENTS

  - x (NArray): a NArray which you want to get difference.
  - dim (Numeric): a Numeric representing the dimention which derivative respect to. you can give number count backward (dim<0), but z.rank ¡Üdim must be > 0.

  RETURN VALUE

  - cdiff_data (NArray): (x_{i+1} - x_{i-1})