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

math-analysis

v0.2.3

Published

Tools for Mathematical Analysis

Downloads

10

Readme

MATH-ANALYSIS

MATH-ANALYSIS can be used to perform various operations pertaining to mathematical analysis such as (symbolic) differentiation, (numeric and symbolic) integration etc.

math-analysis API Documentation

Installation

$ npm install math-analysis

Usage

var ma = require('math-analysis');

ma exposes the following functions:

createFunction (fctSpec)

Creates a function (object) from the given string specification. The specification follows standard syntax, using the following built-in functions:

  • sqrt(x): square root of x

  • log(x): natural logarithm (basis e)

  • exp(x): e to the power of x

  • pow(x,y): x to the power of y

  • sin(x): trigonometric function sine

  • cos(x): trigonometric function cosine

  • PI: constant π

Note: all built-in functions are computed through the respective function offered by Math, i.e. Math.sqrt, Math.log etc.

Example:

var f = ma.createFunction('2.1 * sqrt(x + 1/x)');

The function object created, henceforth denoted by f, has the following methods:

eval(x)

Returns the function value f(x) for the given x.

differentiate()

Returns a function (object) that represents the (symbolically) differentiated f or the derivative of f.

integral(a,b,s)

Computes the integral of f over the interval [a;b]. a and b must be provided and must be numbers. Otherwise the return value is undefined. The integral is computed as F(b) - F(a) for the antiderivative F of f if such an F can be determined (see integrate). Otherwise a numeric approximation of the integral is computed.

In the case of a numeric approach parameter s defines the number of sub-intervals into which [a;b] is "chopped" to approximate the integral. This parameter is an optional integer number not less than 1. If it is not supplied or invalid the default 1000 is used. The bigger the value of s the more accurate the approximation. It will nonetheless remain an approximation. So there is no guarantee that the approximation and the exact value will be the same.

Note that the value of the approximation will be undefined if NaN was encountered when computing the approximation. Keep in mind, however, that the existence of an x in [a;b] for which the function is undefined does not necessarily mean that NaN is indeed encountered. Depending on a and parameter s such an x may be "skipped".

integrate()

Returns the antiderivative of f (as a function). Computation of an antiderivative may not always succeed. If it fails the return value is undefined, which does not necessarily mean that there is no (known) antiderivative. The procedure for computing the antiderivative implemented here has limitations that will be lifted to a certain extent with future versions, but will (or can) never be fully removed. (See also integral).

rewrite()

Returns a function that is a simplified version of f. For instance, x + 0 becomes x and (1+2)*x - x becomes 2 * x etc. Note that rewriting may modify f. That is, rewriting does not return a rewritten copy of f, but rather operates on f itself. Thus, the return value can be ignored as it is merely a pointer to f itself that may come in handy for method-chaining. Hence it is always true that f === f.rewrite().

If for some reason you want to retain f as it was before rewriting simply store its string representation and, if required, apply ma.createFunction to the string to obtain a function object again.

Example
var f = ma.createFunction('x + 0');
var s1 = f.toString();
f.rewrite();
var s2 = f.toString();

Having executed the above code the two string variables s1 and s2 hold the strings 'x + 0' and 'x', respectively.

toString()

Returns the string representation of the function.

lookupTable (fct, from, to, step)

Creates a look-up table for the given function fct with values for x ranging from from to to using the given step size step. fct must have been created with createFunction. The other three parameters are also mandatory and must be of type number. Furthermore, step must be greater than 0 and from must not be greater than to. If any of these prerequisites are not met the return value of this function is undefined.

Example:

var f = ma.createFunction('2*x+1');
var t = ma.lookupTable(f,-1,2.1,0.5);

As a result t is [{x:-1,y:-1},{x:-0.5,y:0},{x:0,y:1},{x:0.5,y:2},{x:1,y:3},{x:1.5,y:4},{x:2,y:5}].