Using Numeric.js to do the cubic spline computation in EJSS
following the documentation here http://web.archive.org/web/20180821215841/http://numericjs.com/documentation.html
and the home URL http://web.archive.org/web/20180821210625/http://www.numericjs.com/
| notice the cubic spline is plotted after the 6 data sets are collected (right panel) |
Model
simulation is available for free here https://iwant2study.org/ospsg/index.php/interactive-resources/biology/1154-photosynthesis-sec
feel free to download the model or source and open the *.ejss file using the EJSS editor. https://www.um.es/fem/EjsWiki/
the code
//var data = ([0,2,3,4,5],[1,2,1,3,2]).at(numeric.linspace(1,5,10))
/*
https://ccc-js.github.io/numeric2/documentation.html
Cubic splines
You can do some (natural) cubic spline interpolation:
IN> numeric.spline([1,2,3,4,5],[1,2,1,3,2]).at(numeric.linspace(1,5,10))
OUT> [ 1, 1.731, 2.039, 1.604, 1.019, 1.294, 2.364, 3.085, 2.82, 2]
*/
var answer = numeric.spline([intensitycubicsplinex[0],intensitycubicsplinex[1],intensitycubicsplinex[2],intensitycubicsplinex[3],intensitycubicsplinex[4],intensitycubicsplinex[5],intensitycubicsplinex[6]],[intensitycubicspliney[0],intensitycubicspliney[1],intensitycubicspliney[2],intensitycubicspliney[3],intensitycubicspliney[4],intensitycubicspliney[5],intensitycubicspliney[6]]).at(numeric.linspace(0,6,24))
splinex = numeric.linspace(0,6,24)
spliney = answer // assign splinex and spliney as X and Y position of an EJSS trace in the intensity of light plot
var answer2 = numeric.spline([carbondioxidecubicsplinex[0],carbondioxidecubicsplinex[1],carbondioxidecubicsplinex[2],carbondioxidecubicsplinex[3],carbondioxidecubicsplinex[4],carbondioxidecubicsplinex[5],carbondioxidecubicsplinex[6]],[carbondioxidecubicspliney[0],carbondioxidecubicspliney[1],carbondioxidecubicspliney[2],carbondioxidecubicspliney[3],carbondioxidecubicspliney[4],carbondioxidecubicspliney[5],carbondioxidecubicspliney[6]]).at(numeric.linspace(0,0.3,24))
splinex2 = numeric.linspace(0,0.3,24)
spliney2 = answer2 // assign splinex2 and spliney2 as X and Y position of an EJSS trace in the percentage of carbon dioxide plot
Summary about Numeric.js
Numeric.js is a powerful JavaScript library for numerical computations that has both strengths and weaknesses.
Strengths:
- High performance for large and complex numerical operations
- Supports many commonly used mathematical functions and operations
- Offers various optimization techniques, such as linear and nonlinear regression, and singular value decomposition
- Easy to use with a simple and intuitive syntax
- Widely used and supported by a large community of developers
Weaknesses:
- Limited support for data visualization, compared to other libraries like D3.js
- Steep learning curve for advanced operations and techniques
- No built-in support for GPU acceleration, making it less efficient for high-performance computations
- Limited compatibility with other libraries and technologies.
Overall, Numeric.js is a strong choice for numerical computations in JavaScript, particularly for its ease of use, performance, and community support, but users may want to consider alternative libraries for specific tasks such as data visualization.
Thanks to an integration of an element called NumericJS in EJSS, currently that seems to a bug, when reopening the *.ejss file, the simulation is missing the element which need a new drag in to allow the simulation to compile properly again.
No comments:
Post a Comment