APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

is it possible to have a JavaScript version of Cubical Spline? post and replies

Return to the is it possible to have a JavaScript version of Cubical Spline? thread
Login to post to this thread

is it possible to have a JavaScript version of Cubical Spline?
lookang Avatar
lookang
245 Posts

Dear Prof Wolfgang,
I been trying to do cubical spline for a set of data to produce a smooth curve.
I open your file here

https://www.compadre.org/osp/items/detail.cfm?ID=11478

there are a lot of old java syntax that I don't know how to convert to JavaScript equivalent. For example.

1. in Variables tab, spline is a type ==CubicSpline, how do I convert to JavaScript?
2. in fixed relationship, code like "y[i]=((org.opensourcephysics.numerics.CubicSpline)spline).evaluate(xi);" is this kind of code working on EJSS or only EJS currently?

I lack the technical knowledge of harnessing the org.opensourcephysics.numerics.CubicSpline library,  Thus, can an EJSS (Javascript) version be released soon? :)

Thank you very much.

Attached File: Screenshot20230126at5.31.55PM.png


OSP@SG blog
OSP@SG Digital Library

Replies to is it possible to have a JavaScript version of Cubical Spline?

Re: is it possible to have a JavaScript version of Cubical Spline? -
Wolfgang
192 Posts

The Cubic spline model that is referenced in this thread was written using the Java version of EJS.  It uses a numerical method from the OSP Java library and that code is attached. Unfortunatley, this cubic spline code has not been implemented in JavaScript.

https://en.wikipedia.org/wiki/Spline_interpolation

The Java shown uses the given (x,y) data to compute the  polynomical coefficients  for the piecewise cubic function.  These coefficients are then used to create an OSP function that is passsed to the OSP graph object.  I recommend that you use a full-featured JavaScript development environment to implement and test the code JavaScript before importing it into a JavaScript EJS model.

The Java OSP library is available on Git Hub for anyone who woild like to do the conversion to JavaScript.

https://github.com/OpenSourcePhysics/osp



Re: is it possible to have a JavaScript version of Cubical Spline? -
lookang Avatar
lookang
245 Posts

Oh, I have successfully implemented cubic spline in this simulation using numeric.js some documentation is available here

https://weelookang.blogspot.com/2023/01/numericjs-to-do-cubic-spline.html

https://iwant2study.org/ospsg/index.php/interactive-resources/biology/1154-photosynthesis-sec

the model is available for use and further editing on the URL above.

thanks for checking!


OSP@SG blog
OSP@SG Digital Library


OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book