I want to calculate the stationary points of a derivative in JavaScript with the external library math.js.
So if I have f(x) = x^2
, the derivative is 2x
and the stationary points can be calculated making 2x = 0
so x = 0
. But the function in math.js that is math.eval
needs to assign a value to x.
For example:
let scope = {
a: 3,
b: 4
}
const c = math.eval('a * b', scope);
console.log(c); // 12
<script src="https://unpkg.com/mathjs@5.0.4/dist/math.min.js"></script>
So how can I calculate 2x + 2 = 0
for example? I want that the result given to me is x = -1
.