-
Notifications
You must be signed in to change notification settings - Fork 19
Documentation
To include JavaScript CAS in your application, download a copy of math.js (minified or development version) and include it in your web page.
The library defines a global object M, which is a function that takes at least one argument to be parsed as a latex string, and an optional secondary argument which is a JavaScript CAS Context object.
A Context is currently implemented as an object which has a key for each variable defined. When parsing (more info on parser) 'x'
with context c
, the value of c['x']
will be used. And if it is not a property of c
then the prototype chain of c
will be searched. All contexts created with the usual var c = new M.Context()
inherit the global functions (sin, cos, etc) from M.Global
via their prototype chain, although JavaScript CAS currently does not require it to be. If you wish to not allow use of these global functions, then you would use a context with c.__proto__
set to Object
.
Every object returned from a M(...)
call is called an Expression, and should always inherit from the M.Expression prototype.
Every Expression has operators defined on it through only its properties. This means that an integer (e.g. two = M('2')
) has functions two['+']
, two['*']
, two['/']
, etc. These functions in the case of Integers are inherited from the M.Expression.Integer
prototype.
This allows some extendability in the sense that you can define operators on individual expressions, or create new classes of mathematical objects.
Expressions also have defined on them the standard features that the CAS provides.
###e.compile('x,y,z') Create a javascript function which evaluates e. Importantly, all variables in the expression must be defined numerically, or specified in function calls.
###e.s(lang) Returns an Code object. Usually, you will want to use the string e.s(lang).s, for lang = 'text/javascript', 'x-shader/x-fragment' or 'text/latex'.
###e.real() Returns the real part of e ###e.imag() Returns the imaginary part of e. ###e.realimag() Returns a ComplexCartesian representation of e. ###e.polar() Returns a ComplexPolar representation of e. ###e.arg() Returns the complex argument of e. ###e.mod2() Returns the modulus squared of e.
###e.differentiate(x) Differentiate an expression with respect to x. Currently only partial derivatives are supported, if that matters. ###e.differentiateN(x, n) Differentiate an expression with respect to x n times. The M.Expression prototype defines this method to differentiate iteratively using this.differentiate. ###e.integrate(x) Integrate with respect to x (indefinite integral) ###e.lim(x,y) Find the limit of e as x approaches y.
###e.factors(x, yes, no) For each factor in e, determine whether it depends on the symbol x. If so, then call yes(factor_i), otherwise no(factor_i). All factors will be passed to these functions before execution of the factors function ends.
###e.terms(x, yes, no) Similar to factors, except that instead of factors, it finds terms dependent on the symbol x.
###e.expand(vars) (Will be removed, use e.terms instead)
###e.roots(vars) Solves the equation e=0 for the array of variables given.
###e.simpliy() Not implemented yet.
###e.dep(vars)
Returns true only if the expression is dependent on at least one of the variables in vars[]
.