A JavaScript plotting library

(start )
(end )
(step )
clamped values
VIEWBOX minx: maxx: miny: maxy:

(start )
(end )
(step )
clamped values
VIEWBOX minx: maxx: miny: maxy:

A bit of API

This library gives you a MathFunction object, which is created with a function string as constructor argument, such as new MathFuction("sin(x) - tan(x) + cos(x^2.4)"). You can also set up a parametric function by using the MathFunction.Compound object, such as new MathFunction.Compound("cos(x)", "sin(x)"). If your function was balanced (i.e. all the opening parentheses have matching closing parentheses) you can use the following API (if unbalanced, the constructor throws an error for you to catch):

render(container)
shows the function as LaTeX in [container]. If MathJax is loaded, typesets it prettily.
plot(container, options, viewbox)
Plots the function, based on the given options: { label: 'var that changes', start: number, end: number, step: number, clamps: [ {label:'var that is clamped', value:number}, ... ]}. If a viewbox is given, of the form {minx:num, maxx:num, miny:num, maxy:num}, the plot will be constrained to those values.

Supported operations

The MathFunction object understands the following operators and functions:

numbers and constants
integer and floating point numbers, supported constants: e, π
basic operators and grouping
...+..., ...-..., ...*..., .../..., ...^..., ...!, -..., (...)
built in functions, of the form fn(...)
sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, ln, log, sqrt, abs
built in aggregators, of the form fn(start, end, [function]), using "n" as control variable
sum, prod
special aggregators
area(start, end, steps, varname, [function]) - this computes the naive Newtonean area underneath a function by, essentially, adding the areas of rectangular strips. I kind of want to replace this with Legendre-Gauss integration, but for now, this works.

Function substitution

The MathFunction object understands variable/function substitution, using the replace function.

replace(varname, [string or MathFunction])
replace all instances of a variable [varname] with the provided MathFunction instead, or if a string was passed, the MathFunction resulting from new MathFunction(string).

This library is still under construction