+ 57
How good is javascript for numerical problems?
I want to solve some differential equations and optimization problems and I'm considering using javascript (I want them to be solved on client-side). Is javascript a good option in terms of performance for these kind of numerical problems?
59 ответов
+ 36
I would be hesitant to use a loosely typed language for serious calculations. There are instances where the built in assumptions of the interpreter can cost you accuracy in a big way.
That said, there is also the comfort factor. The more you know the quirks of the language, the easier you'll find it to work within/around them.
Then again, my earliest calculation programming was with Fortran (which was designed for that kind of work), so I'm a grumpy, old, spoiled dinosaur. YMMV
+ 34
Check this out js for maths. Function derivative - math.js | an extensive math library for JavaScript ...
mathjs.org › docs › reference › functions
+ 32
Jim, I'm a chemical engineer and we still use Fortran to solve problems (it's becoming rare today, but several programs are still based on Fortran)! I'm a professor and I'd like to bring the students closer to flowsheeting problems (simulation of chemical processes) by building examples and even a complete online process simulator, but the equations turn into complex problems fast. If not javascript, what language (for web) would you recomendo?
+ 29
@Filipe, I love JS but I wouldn't recommend a language in which 0.1+0.2 != 0.3 for real Math. If you seek performance Python (numpy, pandas libraries) might be what you are looking for, but if you want it to run in a client's browser you don't have much of a choice.
+ 19
It seems MATLAB, Fortran, C and Javascript use IEEE 754 for double precision. I tested on MATLAB some examples and it produced the same results as javascript. So, in terms of precision, I think javascript is good enough and I can accept those rounding errors. When It comes to physical measurements (like temperature) its hard to measure with confidence even 2 decimal places. I'll keep studying..
+ 17
I also considered Java, but it seems to me that most (or at least chrome) is no longer supporting it by default. Well, all tips here were great! I'll think about them! Thank you!
+ 17
The ecosystem of JS is so huge nowadays. You can google libraries and tools for numerical purposes. I'm sure you can find suitable stuff.
+ 16
@Filipe Coelho I am also a chemical engineering student as now in next semister we have process simulation lab where we use MATLAB and it is best for solving differential equations and such other numerical equations. since it has many built in functions for solving them. But using javascript might possible even better in terms calculating and rounding up values . but it does not have much built in libraries or functions for solving them.
+ 13
Hi Sujeet! Sometimes in chemical engineering we are much more interested solving process design problems then programming problems that arise from modeling and implementation of these models. My idea was develop a simple process simulator that could run on browser for matter of easy of acess. Many students are not familiar with programming languages and process simulators are, in general, expensive or hard to use or both.
+ 12
@Filipe - true (that's was just a popular joke). Python is the same actually, but JS is just not made for Math in my opinion (there might be good libraries out there I just don't know about them). What Python's numpy does with arrays and matrices is really amazing though. The library takes advantage of the CPU's virtualisation and is extremely performant....
+ 11
I miss math operations over matrix like simple sum, but I believe using libraries like math.js or ASM.js, as sugested before here, they may have functions for these operations.
+ 10
Nikolay, if you make this logical test on Matlab, C or Fortran you would probably get the same results because all of them treat floating point arithmetics the same way. For engineering porpuses if this error is not greater then modeling and physical properties uncertainties I can accept it. How does Python treats this floating point problem? Because MATLAB only shows around 14 decimal places and it HIDES the problem from the user.
+ 10
I will take a look on Python too! Thanks for the tip Nikolay!
+ 10
I did some research and tests (I'll share them later) and I think you are right, @Atharv. I found a way of converting C code to JS with emscripten and maybe it's a workaround to the lacking of libraries.
+ 9
If you need speed and a lack of complexity maybe look into python. With a few libraries like numpy, scipy and , maybe, a python compiler, you can make some calculations pretty fast and with a fairly easy to use language. Also it could run from a server.
The bad thing is that every client would need python and the libraries you choose, which could turn tedious and complicated.
If you can get access to some free licenses, try Matlab (they give them free to universities i think). With it you can run simulations and calculations of all kinds. Bad thing is it can be quite heavy and demanding on some laptops
+ 9
What about a java web start application? While it still has potential for configuration issues (like python) for some students, it's client side, but self contained, iirc. That also gives you more structure to work with on the number crunching.
Many colleges have computer labs, which is also a partial solution to the configuration issue (the machines will all be cloned of a standard set of software).
+ 8
I would definitely not go with fortran for a new project. :D
Optimization problems are usually solved with python.
Differential equations is not clear to me, are you talking about ode, pde, sde ?
So usually the integration method is here most important, but i doubt you wanna invest time in implementing integration methods (as a chemical engineer) , therefore i would go with a programming language where you have already existing numerical libraries (Fortran, C/C++, Python, Matlab, but definitely not javascript or java).
Considering also your need for web, you can go with python or what i would do with Qt/C++.
Best Regards
+ 8
Sujeet, thanks a lot for this link! I'm still doing research for the best solution and definetily I'll consider such JS drawbacks.
+ 8
For technical computing, nothing is comparable with MATLAB. It has so many built in functions such ad ode45 for solving ordinary differential equations, pdetool for visually solving partial differential equations, along with many other useful commands. You can simply find the eigenvalues of a matrix by a simple eig command. Also you can define sparse matrices which saves a lot of memory.. It can not be integrated to web, however. But I do all sort of these calculations with Matlab. For instance, I have modeled charge transport between 1 milion organic molecular states with MATLAB.
+ 8
Nikolay, you are almost convincing me! hehehehe Can I integrate Python with html? Like, call Python functions and show the results on HTML element?