GithubHelp home page GithubHelp logo

blakesanie / calculess Goto Github PK

View Code? Open in Web Editor NEW
39.0 2.0 11.0 11 KB

📚 Calculus Library for JS and NPM

License: MIT License

JavaScript 100.00%
math calculus derivative integral limit riemann-sum utils continuity infinity

calculess's Introduction

Calculess.js

A calculus library for javascript. Created by Blake Sanie.

Install

Download using NPM

$ npm install calculess

Download using Yarn

$ yarn add calculess

Embed using jsDelivr

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib.js"></script>

Getting Started

Import and initialize package

var Calculess = require('calculess');
var Calc = Calculess.prototype;

Documentation

Limits

Evaluate a limit

Calc.limAt( x , function );

Evaluate a limit from the left

Calc.limLeftOf( x , function );

Evaluate a limit from the right

Calc.limRightOf( x , function );

Methods:

  • Accept ±Infinity as x value (parameter)
  • Can output ±Infinity
  • Output NaN when the limit does not exist

Examples:

function recip(x) {
    return 1 / x;
}

Calc.limLeftOf(0, recip); // -Infinity
Calc.limRightOf(0, recip); // Infinity
Calc.limAt(0, recip); // NaN
Calc.limAt(1, recip); // 1


Derivatives

Evaluate f'(x)

  • Note: If the given function is not continuous or differentiable at the target, NaN is returned
Calc.deriv( x , function );

Evaluate a derivative to the nth degree of x

  • Note: as the degree increases, .nthDeriv() becomes less accurate. Also, continuity and differentiability are not checked.
Calc.nthDeriv( degree, x , function );

Examples:

function para(x) {
    return x * x;
}

Calc.deriv(2, para); // 4
Calc.nthDeriv(2, 2, para); // 2
Calc.nthDeriv(3, 2, para); // 0

function sharp(x) {
    return Math.abs(x);
}

Calc.deriv(1, sharp); // 1
Calc.nthDeriv(2, 1, sharp); // 0
Calc.deriv(0, sharp); // NaN


Integrals

Evaluate an integral using midpoint Riemann Sums

Calc.integral( start , end , function , numSubintervals );

Evaluate a function's average value

Calc.averageValue( start , end , function , numSubintervals );

Note: As the number of subintervals increases, .intregral() becomes more accurate, though more time is required for calculations

Examples:

function sin(x) {
    return Math.sin(x);
}

Calc.integral(0, Math.PI, sin, 10); // 2.0082484079079745
Calc.integral(0, Math.PI, sin, 100); // 2.000082249070989
Calc.integral(0, Math.PI, sin, 1000); // 2.000000822467294
Calc.integral(0, Math.PI, sin, 10000); // 2.000000008224376
Calc.integral(0, Math.PI, sin, 100000); // 2.000000000081865


calculess's People

Contributors

blakesanie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.