Can i convert math.js object into JavaScript function?

122 Views Asked by At

I'm developing simple js neural network and need to create javascript function (derivative of entered by user) before learning starts.

I know about evaluate(), but i think it'll be slowly than simple function.

That is what i want:

const derivative = math.derivative('x^2/sin(2x)', 'x');
const derivative_func = derivative.please_stay_func();
...
while(1) alert(derivate_func(12)) //:) alert result of (2 * 12 * Math.sin(2*12) - 2 * Math.pow(12, 2) * Math.cos(2*12)) / Math.pow(sin(2*12), 2)

Is it real? And maybe i'm not right about speed. Maybe there is some better ways - write here.

1

There are 1 best solutions below

6
ucup On

i am on mobile, please edit this

maybe this is want you want to do

const countThings = (customValue) ==>{
let x = 'x^2/sin(x)';
let y = 'x';
 x = math.parse(x)
y = math.parse(y)
return math.derivative(x, y).evaluate({x:customValue});}

console.log(countThings(12))

and don't do while(1) alert because it will keep alerting