🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@rec-math/math

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rec-math/math

Mathematics for the browser (and TypeScript, JavaScript).

latest
Source
npmnpm
Version
1.3.0
Version published
Weekly downloads
4
-75%
Maintainers
1
Weekly downloads
 
Created
Source

RecMath mathematics module.

Mathematics for the browser (and TypeScript/Javascript).

Getting started - in the browser

Load RecMath from a CDN

<script src="https://cdn.jsdelivr.net/npm/@rec-math/math@1"></script>

Getting started - Node.js

Install the package with npm i @rec-math/math and import what you want.

import * as RecMath from '@rec-math/math';

Usage

Numerical integration (quadrature)

const [result, info] = RecMath.numerical.quad(
  (x) => Math.exp(-x), // A function to integrate.
  [0, Infinity], // A range to integrate over.
);
console.log(result); // 1
console.log(info);
// { steps: 14, errorEstimate: 3.384539692172424e-16, depth: 7 }

The range can have intermediate points:

const [result, { steps, points }] = RecMath.numerical.quad(
  // Normal distribution.
  (t) => Math.exp(-0.5 * t * t) / Math.sqrt(2 * Math.PI),
  [-Infinity, -3, -2, -1, 1, 2, 3, Infinity],
);

console.log(result, steps); // { result: 1, steps: 32 }

// 68%, 96% and 99.7% confidence intervals.
const oneSigma = points[3][0];
const twoSigma = oneSigma + points[2][0] + points[4][0];
const threeSigma = 1 - points[0][0] - points[6][0];

console.log({ oneSigma, twoSigma, threeSigma });
// {
//   oneSigma: 0.682689492137086,
//   twoSigma: 0.9544997361036417,
//   threeSigma: 0.9973002039367398
// }

FAQs

Package last updated on 29 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts