MathLib.Functn()

MathLib.Functn is MathLib's implementation of mathematical functions.

Unlike all other MathLib constructors `MathLib.Functn` is called without the `new` keyword, due to technical limitations in JavaScript. Most of the times however you probably don't need to call `MathLib.Functn` directly, since MathLib has very many predefined functions.

Examples

Lets say we want to implement the Fermi rounding, which is used in Fermi estimates: $\mathrm{Fermi}\left(x\right)={10}^{\mathrm{round}\left({\mathrm{log}}_{10}x\right)}$ First we have to create the JavaScript function like this: ``` var fermi = function (x) { return Math.pow(10, Math.round(Math.log(x) / Math.LN10)) } ``` Next we decide what our bound variable should be. Lets choose `x` like in the formula above. ``` var args = [MathLib.Expression.variable('x')]; ``` Since MathLib also works with functions that have more then one variable we have to put the variable in an array. Now we can generate the mathematical expression which is describing the function. This is important when modifying the function later. ``` var expr = new MathLib.Expression({ subtype: 'functionDefinition', args: args, content: [new MathLib.Expression({ subtype: 'functionCall', content: args, value: 'Fermi' }) ] }) ``` Finally we can construct the Functn: ``` MathLib.Functn(fermi, { name: 'Fermi', expression: expr }); ```

Properties

.constructor
The function MathLib.Functn
.type
The string "functn"

Methods

.diff()
Numeric derivative at a given point.