mathjs
mathjs copied to clipboard
[Question] Any Numerical Methods or Calculus?
I have been browsing this repo and noticed there doesn't seem to be any functionality for numerical methods for integration, derivatives, interpolation, etc. Is that needed in this repository? I would love to start on that unless it is beyond the scope of this library.
@spencerstith Euler method, Second-order Runge-Kutta methods
Hey Spencer, Thanks for getting in touch! I think that numerical methods are not out of scope – we already have a symbolic derivative and a feature request for symbolic integration (#1015). Numerical integration/derivative would be a great fallback for functions that we can't handle symbolically.
By interpolation I assume you mean something like numpy.interp
. In this regard, I like the idea of creating a new type SampledFunction
which would represent points like [f(0), f(0.1), ... f(1)] for some function f. This would make a clear distinction between vectors and sampled functions (which is missing in numpy). Then, interpolation would take a SampledFunction
and return another, more densely populated SampledFunction
. This would work nicely with FFT (#46) too.
I can imagine that ODE iterators like Euler and Runge-Kutta, which Madan mentions, would also be useful in math.js. But maybe after we have a solver for algebraic equations, so that we can make a consistent API? 🤔 Not sure about this, I'd love to hear your thoughts!
Anyway, starting a new issue about a specific feature would be a great start. Then you (or anyone else) can propose an API and later follow up with a PR :)
@josdejong Any thoughts about this, Jos?
Yes, I would love to have numerical implementations to do integration, differentiation, etc 👍 . Thanks for bringing this up.
Related: #227
Could I take this issue? I can help to implement a Runge-Kutta or maybe some integration algorithms.
Sounds good, thanks for your offer @jjram20 👍 .
Before you work out new functions in detail, please keep us up to date on what exactly you plan to implement and how, so we can discuss where needed.
I could start creating a new folder for numerical methods for calculus inside of /src/functions including a function for numerical integration using the trapezoidal rule, the function would include as parameters the functions that will be integrated as a string and it will be evaluated using the method evaluate of this library, the other parameters will be the limits of integration and the size of increments. The idea is to evaluate using for cycles.
If I am not considering anything, am not being clear, or anything else please let me know.
Yes it makes sense to introduce a new category, "numerical" or "calculus" (what would be the best name?), and create a folder in /src/function
. What functions do you exactly have in mind? numerical integration, numerical differentiation, ...?
For now I would like to start including numerical differentiation (using the definition (f(x+h)-f(x))/h) and numerical integration using trapezoidal rule, and later the next step could be to add other algorithms as Runge-Kutta, but step by step, what do you think about it?
That sounds like a good and realistic plan (not too much at once). Do you have any preference for the name of the category? Ie. "numerical" or "calculus" or something else?
The name of the folder can be "numerical".
Yes I like that best too 👍