NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations!
October 29, 2016, 01:11:31 am

Progress is impossible without change; and those who cannot change their minds cannot change anything. ..."George Bernard Shaw(1865-1950, Irish dramatist, essayist and critic, Nobel Prize for Literature 1925)"

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

Offline

Posts: 3079

 « 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

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
 Logged
lookang
Hero Member

Offline

Posts: 1781

http://weelookang.blogspot.com

 « 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

Posts: 1781

http://weelookang.blogspot.com

 « 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
 « Last Edit: July 04, 2008, 11:11:12 am by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3079

 « 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

Posts: 1781

http://weelookang.blogspot.com

 « 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

Posts: 1781

http://weelookang.blogspot.com

 « 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)
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
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)
 Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3079

 « 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

Posts: 1781

http://weelookang.blogspot.com

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

ok i try

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

 Logged
lookang
Hero Member

Offline

Posts: 1781

http://weelookang.blogspot.com

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

Seems to help solve it  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
Hero Member

Offline

Posts: 3079

 « 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

Posts: 1781

http://weelookang.blogspot.com

 « 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

Posts: 1781

http://weelookang.blogspot.com

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

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

Posts: 1781

http://weelookang.blogspot.com

 « 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 ?
 « Last Edit: July 08, 2008, 03:01:33 pm by lookang » Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3079

 « 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

Posts: 1781

http://weelookang.blogspot.com

 « 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

Posts: 1781

http://weelookang.blogspot.com

 « 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

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

Posts: 1781

http://weelookang.blogspot.com

 « 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
Hero Member

Offline

Posts: 3079

 « 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
lookang
Hero Member

Offline

Posts: 1781

http://weelookang.blogspot.com

 « Embed this message Reply #18 on: April 15, 2016, 11:24:24 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

#JavaScript version plus #Tracker #Modeling
http://iwant2study.org/ospsg/index.php/interactive-resources/physics/02-newtonian-mechanics/01-kinematics/373-kinematicstracker
 Logged
 Pages: [1]   Go Up
Progress is impossible without change; and those who cannot change their minds cannot change anything. ..."George Bernard Shaw(1865-1950, Irish dramatist, essayist and critic, Nobel Prize for Literature 1925)"