Author Topic: relations between displacement/velocity/acceleration  (Read 50151 times)

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
relations between displacement/velocity/acceleration
« on: May 23, 2005, 03: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

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #1 on: July 04, 2008, 10:12:28 am »
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

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #2 on: July 04, 2008, 10:50:32 am »
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 :)
« Last Edit: July 04, 2008, 12:11:12 pm by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: relations between displacement/velocity/acceleration
« Reply #3 on: July 04, 2008, 11: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)
}

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #4 on: July 04, 2008, 12:12:37 pm »
power!!

i will keep in mind

thanks!

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #5 on: July 04, 2008, 04:14:06 pm »
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)

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: relations between displacement/velocity/acceleration
« Reply #6 on: July 04, 2008, 05: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).

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #7 on: July 04, 2008, 06:03:24 pm »
ok i try :)


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


lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #8 on: July 07, 2008, 11:19:46 am »
Seems to help solve it  ;D 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
}

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: relations between displacement/velocity/acceleration
« Reply #9 on: July 07, 2008, 12:10:23 pm »
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;
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
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.

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #10 on: July 07, 2008, 01:52:59 pm »
cool man

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


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
}

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #11 on: July 07, 2008, 01:53:42 pm »
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, 02:07:37 pm by lookang »

lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #12 on: July 08, 2008, 03:58:35 pm »
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 ? :D
« Last Edit: July 08, 2008, 04:01:33 pm by lookang »

Fu-Kwun Hwang

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • Enjoy the fun of physics with simulations
Re: relations between displacement/velocity/acceleration
« Reply #13 on: July 08, 2008, 05:04:57 pm »
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]);



lookang

  • Hero Member
  • *****
  • Posts: 1772
  • http://weelookang.blogspot.com
    • lookang web
Re: relations between displacement/velocity/acceleration
« Reply #14 on: July 08, 2008, 05:33:28 pm »
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.