🚀 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).

Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
4
-66.67%
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.integrate.quad(
  (x) => Math.exp(x), // A function to integrate.
  [0, Number.POSITIVE_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 [, { points }] = RecMath.integrate.quad(
  // Normal distribution.
  (t) => Math.exp(-0.5 * t * t) / Math.sqrt(2 * Math.PI),
  [Number.NEGATIVE_INFINITY, -3, -2, -1, 1, 2, 3, Number.POSITIVE_INFINITY]
);

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

console.log({ oneSigma, twoSigma, threeSigma });
// {
//   oneSigma: 0.6826894921370859,
//   twoSigma: 0.9544997361036416,
//   threeSigma: 0.9973002039367398
// }

FAQs

Package last updated on 13 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