The error will become larger and larger if you try to put function in the "Fixed relations" page instead of define a function.
You might need to have some background about numerical method in order to fully understand it.
I will try to explain it starts with how EJS works:
1. EJS will read "Variables" page: it will ask computer to allocate memory for each variables defined and assigning value to the memory. for example x=5.; it will put 0.05 to memory assigned for x.
2. EJS will read "Initialization" page: This is an optional page. EJS will do whatever java command
3. EJS will read "Evolution" page: This is the page to move time step forward and caculate variable value at the next time step. EJS will use user selected "solver" method to solve the ODE.
4. EJS will read "Fixed relation" page: The system has been moved from time t to t+dt. And java code in this page will be executed. But all the command execute here is done after step 3.
5. EJS will show all the GUI elements according to value assigned to element's properties.
6. EJS will go back to step 3 if it in play mode and continue process 3-4-5 cycles, otherwise it will stop.
Good overview of computing in EJS.
Let me use a simple harmonic motion as examples to explain why relations for derivatives can not be defined in the "Fixed relation page".
If the equation we try to solve is
we will change the above second order differential equation into two first order differential equations:
Evolution page can do first order differential equation, that's cool.
You need to select Runge-Kutta (4th) order to reduce the error.
If the Euler's method were selected , the error will accumuate will soon.
The middle method will reduced error to 10% of the Euler's method .
The error for Runge-Kutta (4th) order is 0.00% of the Euler's method.
And this is the best method for most of the cases.
If you change the above equestions to
dx/dt=vx;(STEP 3 )
dvx/dt=ax; (STEP 3)
and define ax=-k/m*x-b/m*vx; at fixed relation page (STEP 4)
The error will be the same as Euler's method even if Runge-Kutta (4th) order was selectd.
Because EJS use the above equation to move time from t to t+dt (STEP3 to STEP4)
But vx(t) is not the same as vx(t+dt), and x(t) is not the same as x(t+dt)
For Euler's method :
For midpoint method:
Two time steps(t+dt/2 and t+dt) were calculated to move from t-> t+dt.
For Runge-kutta 4th order method:
Four time steps were calculated to reduced the error to 1/10000 as Euler's method.
The right hand side need to be evaluate 4 times. If the correct formula is only available at STEP4.
The right hand side will always be the same , the Runge-kutta 4th order method is not calculated with correct value. The error move back to the same as Euler's method.
You need to read document about Runge-kutta 4th order method to fully understand how the numerical method works and why it can reduced the error.
So i get the idea to always use Runge-kutta 4th order method if i want to reduce computing error.
So is the draw back, responsiveness and speed of using the applet?
Cool, i will remember to use Runge-kutta 4th order method in the future
You need to define function or write the equations into the right hand side of the evolution page, if the right hand side contain variables which is also in the left hand side (like x and vx in the above examples.).[/quote]
Do you mean another tab on the right of evolution page?
If the right hand side did not contain any variables at the left hand side, like k,b,m are all constant . Then, you can defined those at fixed relation page.
I am a bit lost here. ;D
Thanks for the tips.
But it that enough for Z-D ?