Hello! I want to know: 1. Is it possible to define in EJS relation between two variables as Lookup Table (as in Matlab)? 2. How to change a value of the constant when certain condition is met? For example:
IF time>5 THEN spring_constant=10 ELSE spring_constant=5
- 1. Is it possible to define in EJS relation between two variables as Lookup Table (as in Matlab)?
Any relation among variables, such as the one for kinetic energy: K = 0.5*mass*v*v; must be written in a page of Fixed Relations in EJS. These pages are evaluated after each evolution step and after each interaction of the user.
- 2. How to change a value of the constant when certain condition is met? For example:
If the model is based on an ODE, add an Event with Zero value function: return 5 - time;
and action: spring_constant = 10;
If it is not based on an ODE (which I doubt), your if is fine. But make sure the step for t makes it reach t=5 more or less exactly.
Ok. Sorry for the delay. The answer is basically YES. But with caution.
EJS comes with the latest Apache Commons Math library in it. To use it, you just create an duse the objects you need.
I have attached an example where I use your data to create by interpolation a function using Neville's algorithm. This is what Apache says about it:
"Implements the Neville's Algorithm for interpolation of real univariate functions. For reference, see Introduction to Numerical Analysis, ISBN 038795452X, chapter 2."
Once created, you can, in principle, use this function to anything (I use it to plot the function in a smooth way), including the rate part of an ODE.
The caveat is that, depending on your solver, the algorithm to solve the ODE requires the rate function to be "of class C^k". That is the rate function must be differentiable a number of times (k times). For instance, you need C^4 (or was it C^5?) for a Runge-Kutta algorithm to work fine.
I honestly don't know what differentiability you get from Neville's algorithm. But it could every well be a polynomial interpolation, in which case it is just fine.