NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
December 22, 2014, 06:13:10 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
The most important medicine is tender love and care. ..."Mother Teresa(1910-1997, Roman Catholic Missionary, 1979 Nobel Peace Prize)"
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: relations between displacement/velocity/acceleration  (Read 34633 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3058



WWW
«
Embed this message
on: May 23, 2005, 02:29:43 pm »

Registed user can get files related to this applet for offline access.
Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
If java program did not show up, please download and install latest Java RUN TIME

Drag the blue dots in the V-t diagram to set up how the velocity changes as a function of time.
Press play to watch how the x-t and a-t diagrams changed with the setting.



Registed user can get files related to this applet for offline access.
Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
If java program did not show up, please download and install latest Java RUN TIME
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #1 on: July 04, 2008, 09:12:28 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i am trying to make the text to appear which i have not problem with now..


the simple text like


else if (a>-0.1&&a<0.1 ) // v constant

{
title="Speed is uniform(constant)! |v| = "+dvalue(speed)+" m/s ";

}

is very simple to understand and check in java.....


But i have a question,

how to construct the else if checking condition for


1. speed is increasing at constant rate

// is it like this?

else if (  a > 0 && vti > vt ) // how to make java statement to check acceleration is the same as t change?



2. speed is increasing at increasing rate
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: July 04, 2008, 09:50:32 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

no worries,
 i think the position of the codes can solve this problem

when t = t + dt,

speed = 10 + 0.1 let say
run the loop to check
assign speedi = speed inside the loop // forcing speedi = 10 let say.

i seems to have solved it from help from people who know more java than me Smiley
« Last Edit: July 04, 2008, 11:11:12 am by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3058



WWW
«
Embed this message
Reply #3 on: July 04, 2008, 10:46:51 am »

1. how to check if speed is increasing at constant rate ( or acceleration is a constant)

 if( Math.abs(a)!=0 ){ // constant rate could be negative

}

2.  how to make java statement to check acceleration is the same as t change?

if the acceleration is a, define a new variable a2=a.

At constraint page add the following code

if(_isPlaying()){// make sure we only check this when the simulation is playing,
 if(a==a2){// if a(t) is the same as a2(t-dt)

 }
 a2=a; // make a2 equal a(t)
}
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #4 on: July 04, 2008, 11:12:37 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

power!!

i will keep in mind

thanks!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #5 on: July 04, 2008, 03:14:06 pm » posted from:Singapore,,Singapore

any idea how to fix this error message ?

it appears when the applet runs untl the end and stop by itself

java.lang.reflect.InvocationTargetException
   at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.colos.ejs.library.control.MethodWithOneParameter.invoke(Unknown Source)
   at org.colos.ejs.library.control.GroupVariable.propagateValue(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.doTheUpdate(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.update(Unknown Source)
   at org.colos.ejs.library.Animation.update(Unknown Source)
   at org.colos.ejs.library.Animation.step(Unknown Source)
   at org.colos.ejs.library.Animation.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 11
   at weexvav05.weexvav05.getV(weexvav05.java:270)
   at weexvav05.weexvav05._method_for_getV_t__variable(weexvav05.java:337)
   ... 11 more
Exception in thread "Thread-2" java.lang.NullPointerException
   at org.colos.ejs.library.control.swing.ControlNumberField.setValue(Unknown Source)
   at org.colos.ejs.library.control.GroupVariable.propagateValue(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.doTheUpdate(Unknown Source)
   at org.colos.ejs.library.control.EjsControl.update(Unknown Source)
   at org.colos.ejs.library.Animation.update(Unknown Source)
   at org.colos.ejs.library.Animation.step(Unknown Source)
   at org.colos.ejs.library.Animation.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3058



WWW
«
Embed this message
Reply #6 on: July 04, 2008, 04:09:23 pm »

If you open weexvav05.java and check for line 270, you will find out the following:

public double getV (double tt) {
  id=(int)(tt/delt);
 if(id < n){
  a=(yv[id+1]-yv[id])/delt; // formula for acceleration
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
 }
 return 0.; // else id = or > n , return getV(tt) = 0
}

if id equal  n-1, then id+1 will be equal to n which is not available
The maximum number of index is n-1

That is why the error is ArrayIndexOutOfBoundsException

You need to fix the above logical error (run time error).
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #7 on: July 04, 2008, 05:03:24 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

ok i try Smiley


this is  work in progress i have made some customized teaching n learning words.

Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #8 on: July 07, 2008, 10:19:46 am » posted from:Singapore,,Singapore

Seems to help solve it  Grin thanks!
by providing  else if id>n to allow a way to return a value. YA!

public double getV (double tt) {
  id=(int)(tt/delt);
 if(id<=n){
  a=(yv[id+1]-yv[id])/delt; // formula for acceleration
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
 }
 
 // hoping to solve error msg at end of sim
 
else if(id>n){
  a=(yv[id]-yv[id-1])/delt; // formula for acceleration change to calculate backward
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
 }
 
  // hoping to solve error msg at end of sim

 
 
 
 return 0.; // else id = or > n , return getV(tt) = 0
}
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3058



WWW
«
Embed this message
Reply #9 on: July 07, 2008, 11:10:23 am »

No! It is not correct.
If the dimension of yv is n, it means that the index for yv is from 0 to n-1;
Code:
if(id<n){
  a=(yv[id+1]-yv[id])/delt; // formula for acceleration
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
}
Run time error will occurs when id equal n-1.
It is even worse if you changed it to id<=n , because error will occur when id equal n-1 or n.
You could change it to
Code:
if(id<n-1){
  a=(yv[id+1]-yv[id])/delt; // formula for acceleration
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
}
  a=(yv[id]-yv[id-1])/delt; // formula for acceleration change to calculate backward
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
You do not need to add else if(id>=n) , because it will always be satisfied (if it did not satisfied previous if condition).

P.S. I did not check the formula, I only check for logical statement.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #10 on: July 07, 2008, 12:52:59 pm » posted from:Singapore,,Singapore

cool man

it definitely works now, thanks for the useful codes to copy and paste.


Code:
public double getV (double tt) {
  id=(int)(tt/delt);
 
 
  if(id<n-1){
  a=(yv[id+1]-yv[id])/delt; // formula for acceleration
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
}
  a=(yv[id]-yv[id-1])/delt; // formula for acceleration change to calculate backward
  return yv[id]+(t-T[id])*a; // result for  from a = (getV - yv[id] )/ ( t - T[id] )
 
 
// return 0.; // else id = or > n , return getV(tt) = 0
}
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #11 on: July 07, 2008, 12:53:42 pm » posted from:Singapore,,Singapore

added some teaching needs

Kinematics  Animation to illustrate constant speed, increasing s at increasing/decreasing rates, decreasing s at increasing/decreasing rates, etc. Graphs with animation of object moving at the same time

if (t>=20)
{
title1="";

}


 if (vt==getV(t)&&vt>0) // s increasing constant rate, v constant
{
title1="s ="+dvalue(x)+" m "+"is increasing at constant rate";

}

else if (vt>0&&a>0 ) // s increasing at increasing rate
{
title1="s ="+dvalue(x)+" m "+"is increasing at increasing rate";

}

else if (vt>0&&a<0 ) // s is increasing at decreasing rate
{

title1="s ="+dvalue(x)+" m "+"is increasing at decreasing rate";
}


else if (vt==getV(t)&&vt<0) // s decreasing constant rate, v constant
{
title1="s ="+dvalue(x)+" m "+"is decreasing at constant rate";

}

else if (vt<0&&a<0 ) // s is decreasing at increasing rate
{

title1="s ="+dvalue(x)+" m "+"is decreasing at increasing rate";
}

else if (vt<0&&a>0 ) // s is decreasing at decreasing rate
{

title1="s ="+dvalue(x)+" m "+"is decreasing at decreasing rate";
}









// vti = vt;










else // non uniform speed
{
  title="";
//title="Non-Uniform speed! v = "+dvalue(vt)+ " m/s is always changing";
}



« Last Edit: July 07, 2008, 01:07:37 pm by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #12 on: July 08, 2008, 02:58:35 pm » posted from:Singapore,,Singapore

as the user move the green dots T[j], yv[j], how to make they green dots snap to integer values ?

currently the green dots can be any double value which is difficult to use especially if want to explore simple numbers.

for example


i tried change the type to integer but it did not work out.

yv[j] to int but they moved aside to

any tips ? Cheesy
« Last Edit: July 08, 2008, 03:01:33 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3058



WWW
«
Embed this message
Reply #13 on: July 08, 2008, 04:04:57 pm » posted from:Taipei,T\'ai-pei,Taiwan

Define a variable e.g. id and set property "element" for particleSet to id.
When user drag one of the particle, the id will contain the index for the particle.
id will be -1 if none of them were dragged.

if the position of y is yv (which is an array).
set up OnDrag property as following

if(id>-1) yv[id]=(double)((int)yv[id]); // this should work
You can add similar code to others.

 (int)yv[id] will change the type to integer , so the value will be truncated.
But yv[id] is a double so we need to change the type back to double.

yv[id]=(double) ( (int)yv[id]);


Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #14 on: July 08, 2008, 04:33:28 pm » posted from:Singapore,,Singapore

ok i try, i think ur method is neater than the one i did in weexvrelation06.xml
working on 2 files now.

i like the interface of weexvrelation06.xml, but i thought got bug so i moved to weexvav10.xml.

i like the programming of weexvav10.xml as i have recently spent my time here.


Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #15 on: July 16, 2008, 03:14:59 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

Define a variable e.g. id and set property "element" for particleSet to id.
When user drag one of the particle, the id will contain the index for the particle.
id will be -1 if none of them were dragged.

i followed the "set property "element" for particleSet to id."

but i monitor the value of id, it is always zero.

what am i doing wrong Smiley

the rest of the code works! but because the "set property "element" for particleSet to id." didn't work, only the yv[0] works now.
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1729


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #16 on: July 16, 2008, 04:11:09 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

no worries, i finally figure out

In Models - Variables
i assign a new variable
j integer type

In Models - Custom
i added a new function called dsnap()
Code:
public void dsnap () {

// for(int i=0;i 
//yv[i] = yv[i] - (yv[i]%1.0); // for future used change %1.0 to %0.5 if want snap to 0.5 :)

 if(j>-1) yv[j]=(double)((int)yv[j]);

In View
Polygon
Point Selected assign that to the earlier declared variable j
On Drag add the new function as follows
Code:
dragvt();
dsnap();


Debugging purpose:
Add a new field, variable j format "j = 0.0"

works now........no to worry!

« Last Edit: July 16, 2008, 04:48:36 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3058



WWW
«
Embed this message
Reply #17 on: July 16, 2008, 08:38:15 pm »

Yes. You need to define variable in the model. Normally, I will define a variable named "id";

And I will add code like:
Code:
if(id>-1) yv[id]=(double)((int)yv[id]);
in the drag action field.

Please add id>-1 , because id equal to -1 when none of the element was selected.
Logged
Pages: [1]   Go Up
  Print  
The most important medicine is tender love and care. ..."Mother Teresa(1910-1997, Roman Catholic Missionary, 1979 Nobel Peace Prize)"
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.098 seconds with 22 queries.since 2011/06/15