Nouveau Papier Mâché

# npm

Need private packages and team management tools?Check out npm Teams »

## nerdamer

1.1.3 • Public • Published

# Nerdamer

As of version 0.5.0, the library is split into the core and optional add-ons which can be loaded after the core has been loaded.

Getting started with Nerdamer

Some functions have dependencies from other add-ons.

You can see nerdamer in action at http://nerdamer.com/demo

For full documentation go to http://nerdamer.com/documentation

All operations are done using the 'nerdamer' object.

To add an expression just add it to the nerdamer object which will return a expression object.

You can also pass in an object with known values as the second parameter.

As you can see only the substitution is performed. To evaluate the result just call evaluate. Note that evaluate returns a text string or a number not an object.

To get back the text as a fraction, call the text method and pass in the string 'fractions'.

You can get your expression back as LaTeX by calling the toTeX method

To have numbers returned as decimals pass in the string 'decimals' to the toTeX method

Alternatively you can pass an object containing known values into evaluate method instead. The values passed in don't have to be number they can be another expression if needed.

Every time you parse an expression it's stored in nerdamer. To get a list of all the expressions you just call nerdamer.expressions().

You can request it as an object as well by passing in true. This can be convenient in some situations as the numbering starts at 1;

Functions aren't always immediately parsed to numbers. For example

will only subsitute out the variable name. To change this behaviour numer should be passed in as the 3rd argument.

or alternatively

The difference however is that the first option directly substitutes the variables while the second first evaluates the expression and then makes the substitutions. This library utilizes native javascript functions as much as possible. As a result it inherits whatever rounding errors they possess. One major change with version 0.6.0 however, is dealing with floating point issues.

The above expample now returns zero whereas in previous version the result would be 4.440892098500626e-16. Same goes for 0.1+0.2.

An expression can be replaced directly by passing in the index of which expression to override. For example

If multiple modifier options need to be passed into nerdamer you can do so using an array. For example ...

If you need the code as LaTeX you can pass in true as the second parameter when requesting the expressions.

You can specify a particular location when adding an expression, which is specified with the third parameter.

Here's an example of reserved variable and function names.

Most math functions are passed in as part of the expression. If you want to differentiate for instance you just use the function diff which is located in the Calculus add-on as of version 0.5.0

Nerdamer can also handle runtime functions. To do this use the method setFunction. The runtime functions do have symbolic capabilities and support for imaginary numbers. The setfunction method is used as follows:

nerdamer.setFunction( function_name, parameter_array, function_body )

For Example:

Custom functions alternatively be set in following manner.

If you need to add a constant use the setConstant method

To delete just set it to delete

You also have the option of exporting your function to a javascript function which can be useful if you need some filtering from user input. Do keep in mind that the parameters are sorted alphabetically for more than one parameter. To use it add the expression to nerdamer and use the buildFunction method.

If you have a particular order in which you need the parameters to be set, then you pass in an array with the variables in the order in which you want them for instance:

Every time you add an expression to nerdamer it's stored. To list the expressions currently in nerdamer call the 'expressions' method. To delete an expression use the 'clear' method and pass in the expression you want to delete. To clear everything pass in the string 'all'.

If you need go get the variables of an expression use the variables method. This method can be called after nerdamer was provided an expression. For example

The order in which the variables appear require a little bit of knowledge of how nerdamer organizes symbols. For the sake of simplicity we'll just assume that there is no particular order

# Using the solver

To solve equations first load Solve.js. Just remember that Solve also required Algebra.js and Calculus.js to be loaded. You can then solve equations using nerdamer. Important: State the variable for which you are trying to solve.

Notice that we use toString rather than text as this returns a javascript array.

You can also solve an expression

You can also solve multivariate equations

You can do up to 3rd order polynomials for multivariate polynomials

Additionally you can try for equations containing functions. This is more of a hit or miss approach unlike single variable polynomials (which uses Mr. David Binner's Jenkins-Traub port - http://www.akiti.ca/PolyRootRe.html) but it's there if you want to give it a try.

To solve a system of linear equations pass them in as an array. For example

In version 0.7.2 and up the solver can additionally be used in the following way

### Install

npm i nerdamer

433

1.1.3

MIT

1.27 MB

25

### Homepage

nerdamer.com/

### Repository

github.com/jiggzson/nerdamer