npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

brents-method

v2.0.1

Published

A root solver for functions using Brent's Method.

Downloads

25

Readme

Brent's Method

Description

Brent's Method is a novel, highly efficient method for finding the roots of a function within given bounds - that is, where the function returns 0 (or very nearly 0), also known as an x-intercept.

Wikipedia's entry reads:

In numerical analysis, Brent's method is a root-finding algorithm combining the bisection method, the secant method and inverse quadratic interpolation. It has the reliability of bisection but it can be as quick as some of the less-reliable methods. The algorithm tries to use the potentially fast-converging secant method or inverse quadratic interpolation if possible, but it falls back to the more robust bisection method if necessary.

Example

const brentMethod = require('brents-method')

brentsMethod(
  x => (x + 3) * Math.pow(x - 1, 2),
  -4,
  4 / 3,
) // -3

Parameters

| Param | Type | Default | Description | | --- | --- | --- | --- | | f | function | | The function for which roots are desired. | | lowerLimit | Number | | The lower value used to bracket root finding into the function. | | upperLimit | Number | | The upper value used to bracket root finding into the function. | | options | Object | | An optional arguments object. | | [options.errorTolerance] | Number | 1e-7 | Used to determine how close the bounds bracketing root finding must converge before quitting. | | [options.maxIterations] | Number | 50 | The maximum number of iterations before root finding will fail. |

Specifics

In my implementation, the inverse quadratic interpolation is applied directly. In other cases, the Lagrange polynomial is reduced by defining the variables p, q, r, s, and t, and the x value is not overwritten with the bisection method, but modified. For simplicity's sake, the inverse quadratic interpolation is applied directly in this implementation and the new guess is overwritten if needed.

This is based in part on a number of other implementations and references.

Useful references: https://www.youtube.com/watch?v=-bLSRiokgFk https://en.wikipedia.org/wiki/Brent%27s_method#Brent's_method https://en.wikipedia.org/wiki?title=Talk:Brent%27s_method#Removed_code

Gotchas

Several implementations I have seen contain a common error, which I carefully corrected. The bug isn't fatal, but can cause the algorithm to run extra iterations. Two of these are listed below, both as useful references and as a warning to avoid this error.

One in Julia And one in C++

Testing

npm test

If you have suggestions for particularly trying functions, or better tests, please hit me up 😁

TODO:

  • [ ] More thorough description than a wiki link
  • [ ] Usage stats

Feedback ✉️

Website 🌐

[email protected]

https://github.com/limeandcoconut 🐙😸

@limeandcoconut 🐦

Cheers!

License

ISC, see license for details.