hausen / math.diff.js

Symbolic differentiation plugin for Math.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

math.diff.js

A plugin for Math.js that calculates symbolic derivatives in JavaScript.

Demo: https://rawgit.com/hausen/math.diff.js/master/demo.html

Suggestions, bug reports and pull requests are welcome!

Usage

  1. Load the necessary files
<!-- load math.js first... -->
<script src="math.js"></script>
<!-- ... and then load math.diff.js -->
<script src="math.diff.js"></script>
  1. Differentiate an expression
var expr = math.parse("4*x^3 + 3*x^2 + 2*x + 1");
var derivative = math.diff(expr, "x");

What works

Arithmetic operations: +, -, *, / and ^.

Functions: sqrt, log (natural logarithm), sin, cos, tan, sec, csc, cot. For any other function f, its derivative will not be explicitly evaluated; instead, it will be represented by f'.

Constants: e and pi.

Some trivial simplifications, such as 2*3*x = 6*x are performed.

Todo

Implement inverse trigonometric functions.

Handle multivariable functions.

Improve simplification.

Unit tests.

Why?

I am teaching a course on numerical analysis and wondered if there was a simple way to calculate symbolic derivatives on a web page without relying on a server. I tried a couple of JavaScript libraries that should do the trick, but they didn't work as expected; to make matters worse, they were huge and seemed to be unmaintained.

Also, it was late in the night, I was bored and sleepless.

License

GNU Affero Public License v. 3.0

Thanks to

verteu

About

Symbolic differentiation plugin for Math.js

License:GNU Affero General Public License v3.0


Languages

Language:JavaScript 88.5%Language:HTML 11.5%