-
-
Notifications
You must be signed in to change notification settings - Fork 30
Algebra
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 objectYou can also create function using real JS code:
const f = t.f(x => 2*x + 1) // => TheoremJS function objectYou can "run" these functions (or polynomials) using run:
t.run(f, 5) // = 11You 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 objectThe following functions 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']You can easily get the derivative of any polynomials using derivative:
t.derivate(t.polynomial(1, -1, -1)) // f(x) = 2x - 1 => TheoremJS polynomial objectYou can get the slope of a function at any number x like that:
t.slope(t.f("x", "x ** 2"), 2) // 4 => BigNumberSame as derivative but for integrals:
t.integrate(t.polynomial(1, -1, -1) // f(x) = x^3/3 - x^2/2 - x + 0 => TheoremJS polynomial objectYou can get the gradient using 2 points like that:
t.gradient({
2: 3
}, {
6: 8
}) // => 1.25Will work for any functions You can solve an equation like
f(x) = yusingnumeralSolve:
t.numeralSolve(t.f("x", "2*x+1"), 0) // => ['-0.5', 0] , Returns -0.5 with 0 error rateYou can choose the range by adding arguments like:
... from = -100, to = 100, step = 0.1
Get f(0)
t.y_intercept(t.f("x", "2*x+1")) // => 1Any questions? Don't hesitate to create an issue and tell me about your problem 😊.
Copyright © 2017-2018 Arthur Guiot