GithubHelp home page GithubHelp logo

js-solver's Introduction

##js-solver ###algebraic equation solving helper library

##include

//node.js
npm install js-solver
var Solver = require('js-solver')
//browser
<script src='js-solver.js'></script>

##usage

var mySolver = new Solver({
  a: 'b+c',
  b: 'a-c',
  c: 'a-c'
})

mySolver.solve({
  b: 2,
  c: 3
})
/* solved for 'a' based on equation
  {
    a:5, b:2, c:3
  }
*/

##more in depth example

var triangleSolver = new Solver({
    area: 'base*h/2',
    c: 'Math.sqrt(Math.pow(a,2)+Math.pow(b,2)) || base/2', //base/2 is an example of a dual-equation definition
    a: 'Math.sqrt(Math.pow(c,2)-Math.pow(b,2))',
    b: 'Math.sqrt(Math.pow(c,2)-Math.pow(a,2))',
    h: 'area*2/base',
    base: 'area*2/h'
})
triangleSolver.solve({
    c: 5,
    b: 3,
    area: 50,
    h: 10
})
/*
  { c: 5, b: 3, area: 50, h: 10, a: 4, base: 10 }
*/

##Bonus These are also valid equations

'a^2+b^2' //^ == power
'sqrt(c**2-a**2)' //** == power - from python, also notice sqrt, without the Math. in front (see note)

###Valid Math defaults:
abs acos asin atan atan2 ceil co exp floor log pow E PI sin sqrt tan

##notes: The equations are evaled, so be aware of that. Also I used with(Math) to get the math stuff to eval... yeah...

js-solver's People

Contributors

zolmeister 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

Watchers

 avatar  avatar  avatar

Forkers

mdaparte

js-solver's Issues

method

hello, whst method the library uses for? thanks

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.