mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

[Question] Any Numerical Methods or Calculus?

Open spencerstith opened this issue 3 years ago • 12 comments

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 avatar Aug 21 '21 02:08 spencerstith

@spencerstith Euler method, Second-order Runge-Kutta methods

Madanaa avatar Aug 22 '21 06:08 Madanaa

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 :)

cshaa avatar Aug 23 '21 12:08 cshaa

@josdejong Any thoughts about this, Jos?

cshaa avatar Aug 23 '21 12:08 cshaa

Yes, I would love to have numerical implementations to do integration, differentiation, etc 👍 . Thanks for bringing this up.

Related: #227

josdejong avatar Sep 15 '21 09:09 josdejong

Could I take this issue? I can help to implement a Runge-Kutta or maybe some integration algorithms.

jjram20 avatar Dec 16 '21 18:12 jjram20

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.

josdejong avatar Dec 19 '21 16:12 josdejong

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.

jjram20 avatar Dec 22 '21 00:12 jjram20

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, ...?

josdejong avatar Dec 22 '21 07:12 josdejong

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?

jjram20 avatar Dec 22 '21 09:12 jjram20

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?

josdejong avatar Dec 22 '21 10:12 josdejong

The name of the folder can be "numerical".

jjram20 avatar Dec 22 '21 17:12 jjram20

Yes I like that best too 👍

josdejong avatar Dec 22 '21 19:12 josdejong