joelahoover / mathjs-simple-integral

Extends Math.js to be able to compute simple integrals.
Apache License 2.0
37 stars 9 forks source link

Cant import module #3

Closed MAGNETO903 closed 4 years ago

MAGNETO903 commented 4 years ago

I tried: Code: var math = require('mathjs') var math2 = math.create(math.all) math2.import(require('mathjs-simple-integral'));

But this returned: Error: Cannot import "factory": already exists

What can i do?

joelahoover commented 4 years ago

This library was developed against version 3.18.1 of math.js, whereas the most recent version of math.js is 7.0.0. That is quite a few major versions where things could break! It has been years since I've looked at this project or math.js (nor do I have the time now to jump back in to this project), so unfortunately I don't have any insights into the changes required to make this library compatible with modern versions of math.js.

If you want to get this working, you can either use an old version of math.js (if that works for your use case), or you can dive in to the code yourself and try to debug what the issue is. I would probably start by finding which version of math.js introduced the incompatibility, and then looking at the changelog for any clues.

Finally, before you invest any time with this, I'd recommend you take a close look at the "Limitations" section of the README and see if this library is powerful enough for your use case, because the approach used here (and the currently defined integration rules) are rather limited.

MAGNETO903 commented 4 years ago

Yes! I found in changelog of library math.js after version 6.0.0 there were breaking changes. But i did as it was written and now everyting works!

var create = require('mathjs').create;
var all = require('mathjs').all;
const mathjs = create(all)
mathjs.import(require('mathjs-simple-integral'))

console.log(mathjs.integral('x^2', 'x').toString()); // 'x ^ 3 / 3')

But... Unfortunatly your module cant calculate difficult integrals such as:
3sin(2x)cos(x)^4 3sin(2x)sin(x)^4 (5(ln(5x))^4)/x

JThobbyist commented 4 years ago

I patched the integral.js file to make it importable by mathjs 7.0.1. I created a pull request for it, please accept it/merge it/ whatever it is called (I’m a lot better with JS than I am with GitHub lol)