Skip to content

Algebra

Arthur Guiot edited this page May 14, 2018 · 7 revisions

In order to create a function, you'll need to use the f function like that:

const f = t.f("x", "2*x+1") // => TheoremJS function object

You can "run" these functions using run:

t.run(f, 5) // = 11

You can create polynomials using polynomial like that:

const poly1 = t.polynomial(2, 1) // f(x) = 2x + 1 => TheoremJS polynomial object
const poly2 = t.polynomial(3, 2, 1) // f(x) = 3x^2 + 2x + 1 => TheoremJS polynomial object

Find Roots

This will only work for polynomials

You can find the roots of a polynomial using findRoots. It will return an array of Strings that you can parse using eval() in JavaScript to get the solution as a number.

Example:

t.findRoots(t.polynomial(1, -1, -1)) // => ['(1 + Math.sqrt(5)) / 2', '(1 - Math.sqrt(5)) / 2']
Clone this wiki locally