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-script

v1.1.0

Published

This is a test of my first npm based website

Downloads

29

Readme

Build Status Coverage Status MIT license

Math-Script

A math library for JS with an emphasis on matrix operations, non linear solvers, visualizations, and overload support!.

var M = require('math-script');

M.execute(function(M){
    var X = M.range(0,0.1,10); // Create an input matrix, [100,1] matrix 
    // Your typical ugly JS math library 
    var Y = X.pow(3).multiply(-1.3).add(X.pow(2).multiply(13)).add(X.multiply(-5)).add(30);
    // What math-script supports
    Y = -1.3*X**3 + 13*X**2 + -5*X + 30; // not normally possible in JS
    console.log(Y.print());
});

Core features:

  • Matrix operations operator support in execute environment *, +, **, -
  • Feature rich [M,N] matrix operation support, see reference
  • SVD support / Nonlinear solvers

Install

NPM Installation:

npm install math-script 

Browser minimal:

See dist folder for files

<script type="text/javascript" src="math-script.js"></script>

Math-Script with Plotting

<script type="text/javascript" src="plotly.min1.19.2.js"></script> 
<script type="text/javascript" src="math-script-full.js"></script>

Library Application Sample

Linear Regression Example:

This example uses linear least squares to identify a best fitting polynomial to arbitrary data. This example demonstrates the matrix and plotting functionality of libary.

var X = Matrixs.range(-1.2, 0.01, 1.2); // Creates a matrixs with a range of values 
var Y = X.pow(3).subtract(X).addNoise(0.9); // Y = X^3 - X + noise 

// Create a column matrix for a least square solution [x^3,x^2,x,1] 
var A = X.pow(3).catH(X.pow(2)).catH(X).catH(Matrixs.ones(X.length(),1)); 

var x = A.lsq(Y); // Least squares solution 
var yFit = A.multiply(x); // Ax = Y 
plotyLayout.showlegend= false;
plotyLayout.title= 'Least Square Example'; 
Plots.create([X,Y],{type:'scatter'}); 
Plots.add([X,yFit]);

Basic Matrix Examples

Maths.js supports numerous matrixs opperations. Below is small sampling and see here for the matrixs reference.

Matrix Creation:

var A = Matrixs.make([[1,2,3],[4,5,6],[7,8,5]); //creates a 3x3 matrix 
A.print(); //prints matrix 
//Results 
//1.000		2.000		3.000
//4.000		5.000		6.000
//7.000		8.000		5.000

Matrix Opperations (Addition, Multiplicaiton ...ect): One can add or perform any basic matrix opperation with scalars or other matricies. These commands can be sequentially chained.

var A = Matrixs.make([[1,2,3],[4,5,6],[7,8,5]); //creates a 3x3 matrix 
A.add(1).add([[1,2,3],[0,0,0],[0,0,0]]).print(); // adds scalar of 1 to matrix, then adds a 3x3 matrix, then prints result.
//Results
//3.000		5.000		7.000
//5.000		6.000		7.000
//8.000		9.000		6.000

Matrix Inversion: Maths.js can invert arbitrary sized(e.g. 100x100) singular and non singular(with SVD) matricies.

var A = new Matrixs([[1,2,3],[4,5,6],[7,8,9]]); //creates a 3x3 matrix
A.invert().print(); //Prints after inverison. Print is set to 3 decimals 
//Results: 
//-0.639        -0.167		0.306
//-0.056        0.000		0.056
//0.528         0.167      -0.194

Basic Plot Example

Simple Line and Scatter Plot :

Maths.js can easily create plots for visualization. Please see here for the plot reference. . The backbone of this library is plotly whos backbone is D3 meaning the plots are SVG based.

var X = Matrixs.range(100); // Creates a 0-99 value array
var Y = X.addNoise(0.9); // Adds 90% relative noise 
Plots.create([Y],{type:'scatter'}); //Creates scatter plot 
Plots.add([X]); // Adds orange best fit line 

License: MIT

https://opensource.org/licenses/MIT