integrate-simpson

Integrate a function of one variable using Simpson's Rule

integrate-simpson

Integrate a function of one variable using Simpson's Rule

Introduction

This module computes the integral

using Simpson's Rulethat approximates the function with quadratic segments. The summation is computed using the formula

where for with .

This method is simple and easy to control but not particularly efficient. For an adaptive version of the same algorithm see scijs/integrate-adaptive-simpson.

Install

$ npm install integrate-simpson

Example

var simpson = require('integrate-simpson')

// Integrate sin(x) from 0 to pi using ten intervals
simpson( Math.sin, 0, Math.PI, 10 )
// => 2.000006784441801

API

require('integrate-simpson')( f, a, b, n )

Arguments:

  • f: The function to be integrated. A function of one variable that returns a value.
  • a: The lower limit of integration, .
  • b: The upper limit of integration, .
  • n: The number of intervals, equal to the number of quadratic segments. Results in function evaluations.

Returns: The value of the integral

Credits

(c) 2015 Ricky Reusser. MIT License

Repository

https://github.com/scijs/integrate-simpson


上一篇:gulp-markdown-equations
下一篇:pickadate

相关推荐

官方社区

扫码加入 JavaScript 社区