NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 20, 2020, 03:15:01 pm

"There is nothing either good or bad, but thinking makes it so." ..."Shakespeare (154-1616, English dramatist and poet) "

 Pages: [1]   Go Down
 Author Topic: how to view the valuesofvariables declared inside for ODE Evolution Page in EJS?  (Read 5767 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member

Offline

Posts: 1796

http://weelookang.blogspot.com

 « Embed this message on: November 28, 2008, 09:19:14 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

how to view the values of variables declared inside for ODE Evolution Page in EJS?

For example,
Code:
double deltax = x[1]-x[0], deltay = y[1]-y[0]; //
double deltaVx = vx[1]-vx[0], deltaVy = vy[1]-vy[0];
double distance = Math.sqrt(deltax*deltax+deltay*deltay)-diameter/2*2;  //
if (deltax*deltaVx+deltay*deltaVy<0) {
return distance;
}
Action:
Code:
double vcmx = (vx[1]+vx[0])/2;  // vcm is center of mass velocity in laboratory
double vcmy = (vy[1]+vy[0])/2;
double deltax = x[1]-x[0], deltay = y[1]-y[0];
double r=Math.sqrt(deltax*deltax+deltay*deltay);  // separation
deltax = deltax/r;  // normalized separation x component
deltay = deltay/r;  // normalized separation y component
// transform into CM system
vx[0]=vx[0]-vcmx;
vy[0]=vy[0]-vcmy;
vx[1]=vx[1]-vcmx;
vy[1]=vy[1]-vcmy;
// compute collisions
double dot=deltax*vx[0]+deltay*vy[0]; // particle 0 projection along line of centers
vx[0]=vx[0]-2*dot*deltax;
vy[0]=vy[0]-2*dot*deltay;
dot=deltax*vx[1]+deltay*vy[1];  // particle 1 projection along line of centers
vx[1]=vx[1]-2*dot*deltax;
vy[1]=vy[1]-2*dot*deltay;
// transform into laboratory
vx[0]=vx[0]+vcmx;
vy[0]=vy[0]+vcmy;
vx[1]=vx[1]+vcmx;
vy[1]=vy[1]+vcmy;

I normally recreate the variables in event in the main variable tab/page and copy and paste the relationship/equation in "fixed relations tab" to track the values as the simulation run.

Example of Fields: that i want to see what they are calculating
deltax = 0.00
deltay = 0.00
deltaVx = 0.00
deltaVy = 0.00
distance = 0.00

is there an easier way to do track variables declared inside the event and for the matter custom functions ?  Thanks!
 « Last Edit: November 28, 2008, 09:36:49 am by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3086

 « Embed this message Reply #1 on: November 28, 2008, 11:03:57 am »

In the custom page, you declear variable as local scope:

double deltax = x[1]-x[0], deltay = y[1]-y[0]; //
double deltaVx = vx[1]-vx[0], deltaVy = vy[1]-vy[0];
double distance = Math.sqrt(deltax*deltax+deltay*deltay)-diameter/2*2;  //

So deltax,deltaVx and distance are only available in the custom page.

If you want to use those variable (or any variable globally). Define variable in the Variable tabs.
And you can access all variables defined in the Variable tabs anywhere in the ejs program.

So you need to define deltax,deltaVx and distance , and change the above code to
deltax = x[1]-x[0], deltay = y[1]-y[0]; //
deltaVx = vx[1]-vx[0], deltaVy = vy[1]-vy[0];
distance = Math.sqrt(deltax*deltax+deltay*deltay)-diameter/2*2;  //

And you can assign the above variables to any view element to find out their value!
 Logged
 Pages: [1]   Go Up
"There is nothing either good or bad, but thinking makes it so." ..."Shakespeare (154-1616, English dramatist and poet) "