Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 1.23 KB

gradient.md

File metadata and controls

65 lines (43 loc) · 1.23 KB

gradient

Estimate derivatives from adjacent sample differences.

API

Numeric.math.gradient(samples, spacing = 1, level, target)

Estimates derivatives from adjacent sample differences.

  • Parameters:
    • samples: Sampled values to differentiate
    • spacing: Distance between consecutive samples
    • level: Optional axis or second-axis spacing for a two-dimensional gradient
    • target: Optional axis when per-axis spacings are provided
  • Returns: Gradient estimates for each interior sample
  • NumPy: Equivalent to np.gradient.

Examples

Gradient of a sampled vector

import Numeric from '@neabyte/numerix'

const values = Numeric.math.gradient([1, 2, 4, 8])

console.log(values)
// [1,1.5,3,4]

Gradient with a custom sample spacing

import Numeric from '@neabyte/numerix'

const values = Numeric.math.gradient([1, 2, 4, 8], 2)

console.log(values)
// [0.5,0.75,1.5,2]

Gradient of a quadratic sample

import Numeric from '@neabyte/numerix'

const values = Numeric.math.gradient([0, 1, 4, 9, 16])

console.log(values)
// [1,2,4,6,7]

Gradient of a short sample

import Numeric from '@neabyte/numerix'

const values = Numeric.math.gradient([5, 5])

console.log(values)
// [0,0]