NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Dynamics => Topic started by: lookang on July 10, 2007, 11:47:56 pm



Title: how to make the text b always appear after the simulation is reset?
Post by: lookang on July 10, 2007, 11:47:56 pm
i making a inquiry based applet that allows user to reset the simulation
but the graph is constantly being updated and shows the Xmax for different driving frequency

so as to achieve the graph of maximum amplitude versus different driver frequencies ?

Thanks


Title: graph to show this
Post by: lookang on July 10, 2007, 11:52:55 pm
(http://)



Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 11, 2007, 11:08:55 am
If you want to create it with EJS. Use _initialize() function to change the initial value, instead of calling _reset().
_reset() will reset everything, including all the variables.
You can find similar example at Blackbody radiation curves for different temperatures  (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=427)


Title: how to make a variable assignment when the pause button is pressed
Post by: lookang on July 19, 2007, 03:57:08 pm
Hi community of practice a.k.a. Prof. Hwang  :D

i am trying to assign Xmodplot = Xmod; when pause button is pressed



if(_pause()){
 
Xmodplot = Xmod;
 }


The reason is i need the user to decide when is it that is maximum amplitude by clicking the pause button


Generating simulation file
  F:\EasyJavaSimulations\Ejs3.46_070428\Ejs\Simulations\_apps\_examples\weelookangresonance03.app\weelookangresonance03.java ...
F:\EasyJavaSimulations\Ejs3.46_070428\Ejs\Simulations\_apps\_examples\weelookangresonance03.app\weelookangresonance03.java:297: incompatible types
found   : void
required: boolean
    if(_pause()){
             ^
1 error
Compilation produced an error!


Title: no worries i did it :) by refering the binary.xml
Post by: lookang on July 19, 2007, 04:48:22 pm
public void playPause () {

 if(label=="play"){
  label="pause"; // to assign label="pause"
  _play();


 }else{
  label="play";
  _pause();

Xmodplot = Xmax; // to allow user to decide maximum amplitude
 }





}


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: lookang on July 20, 2007, 08:25:38 am
Hi community of practice a.k.a. Prof. Hwang   ;D

i am trying to make graphing the user understand resonance


so everytime the button is pressed to determine the Xmaxplot and the graph will remember to plot

coordinates,

(Hertz ,Xmaxplot[0])
(Hertz ,Xmaxplot[1])
(Hertz ,Xmaxplot[2])
(Hertz ,Xmaxplot[3]) and on to achieve understand of resonance for a particular damping first.


can advise how to do that?
currently it just plot (Hertz ,Xmaxplot[1]) then it goes on to plot (Hertz ,Xmaxplot[2]) so i am missing the previous data.


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 20, 2007, 10:20:34 pm
I am in Malaysia now.
For your previous question: You should use
if(_isPlaying()){
}
or if(_isPaused()){
}

For status of simulation. _pause() is an action to pause the simulation.
_play() us an action to start the simulation.

There are several ways to do what you want to do.
You can use polygon to plot the data
provide Hertz as x property, and Xmaxplot as y property.
Define ns=0 (interger) to record number of data point recorded.
When ever user click button, add action in the property field.
for example: Xmaxplot[ns]=xxx (name of the variable you want to save)
and ns=ns+1;
and set the number of polygon to ns;



Title: Re: how to make the text b always appear after the simulation is reset?
Post by: lookang on July 24, 2007, 01:34:08 pm
A bit lost on that part

is there an example file to follow the logic and syntax :)




Quote:
"When ever user click button, add action in the property field.
for example: Xmaxplot[ns]=xxx (name of the variable you want to save)
and ns=ns+1;
and set the number of polygon to ns;"


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 24, 2007, 02:58:06 pm
I can not give you detail example because I have no ideas about your model for the simulation.

I only know you want the simulation to remember a set of data points and you want to show those data points.
So you need to define variables to save those data points. For examples: npt=100 (maximum number of points to be saved), xs[npt],ys[npt], np=0;// number of points been saved
Add the following to the press action property for button
xs[np]=x;
ys[np]=y;
np=np+1;

And you can display it with polygon elements in GUI.
Set number of data to be shown as np;
x,y coordinates to xs,ys
Then EJS will take care of the rest for you!

If you can upload your ejs source files and describe in more detail what you want to do, I can try to modify your ejs code to suit your need.


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: lookang on July 24, 2007, 10:00:20 pm
i followed the idea from your post.

seems ok  ;D

it is able to compile

but i can't seems to understand the logic of

xs[np]=Hertz;         // i self improvised your 'x' to mean 'Hertz' in my xml
ys[np]=Xmodplot;    // your 'y' to mean 'Xmodplot'
np=np+1;


After clicking on the button on the extreme bottom right , np=np+1; is executed !!

but my variable xs[np] and ys[np] doesn't seems to be doing what i wanted to assign

xs[np]=Hertz;
ys[np]=Xmodplot;


The main thing i wanted is to give users a chance to manually plot out (using EJS) for a particular damping coeff. b

to plot maximum amplitude resonance (Xmodplot) versus frequency of driver (Hertz), so that the experience of experimenting with the system simulation allows a deeper sense of the graphs. (refer to previous post for the picture)

this is a really difficult concept to explain in real life ( i used a water bottle and my hand to act as the driver, to demonstrate resonance ). :D

attached is the xml, thanks for taking time to help me


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 25, 2007, 08:37:22 am
You have a very complicated model in the code. I did not understand them all.
However, I found some syntax error in the code.
1. xs,ys should be an array. So I would suggest you put [npt] in the dimension field for those variables.
2. I add xsp,ysp to display value in the textfield
3. I also modified the action in the Pause22 VIEW element.
I modified your code, however, I do not know how to change those parameters/values. ys always give me 1.
Please check out the modified code.


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: lookang on July 25, 2007, 11:23:46 am
Hi Prof.Hwang

the mathematical model is a spring mass system with air resistance.

Lucky for the EJS manual from Prof. Paco, the evolution equation are given.

The complexity arises due to my attempt

1. to make it into a applet where users can conduct their own experiment
2. instructional design more friendly ( text etc)
3. greater control to study certain quantities alone or together ( checkbox etc)
4. my lack of knowledge in javascripts (i am learning by refering to examples for syntax and logic)
5. use of the fields to debug and make sense what they mean in xml codes

which is why i don't get what xsp and ysp do  ??? it is because i use the wrong field (old) 1.0 type ?

maybe i try to change to 2.0 type of field  :D

Thanks to you and prof. paco, the learning journey is tough but i hope to be good enough some day.


Anyway, back to the xml file, i think the polygon is not what i wanted because the user need

To get one plot point:

1. wait for oscillation to be "steady";
2. change Xmax to zero;
3. wait for Xmax to become highest or steady;
4. pause simulation;
5. click on button to store Xmodplot = Xmax;
6. change frequency to another value
7. set Xo = 1 m again
8. click play

All these just to get one point to plot .

To get another data point:

repeat 1 to 8





Question of Choice of Polygon.
Is it better to be particleset ? i was thinking to show big dots (user has to conclude on their own) rather than a line which the user can conduct very few data points or in not increasing order of frequency.

I try to work on it at home later.

Thanks for help  :)


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 25, 2007, 04:44:11 pm
You can use particleset or trace for your case.
"Particleset" only show points as small dots, however, trace will connect points with line.
You can play with it or look at the examples. You should be able to find examples for most of the GUI elements.
It is under Simulations/_examples/Elements/

If you have some background in programming, you should be able to pick up ejs in a short time.
I just went to University of Malaysia to for 3 days EJS workshop last week, to teach their faculty members how to create simulation with EJS. Please check out the examples in this forum. If you can understand Chinese language, there are more information about EJS at my online ejs course. (http://enjoy.phy.ntnu.edu.tw/course/view.php?id=246) You will find many step by step examples shown as flash movie.


Title: excellent! It WORKS beautifully now!!
Post by: lookang on July 26, 2007, 01:35:11 pm
It WORKS beautifully now!!

Thanks for your kind assistance. I won't have been able to accomplish without your help and prof. paco. 

reporting bug:

I change to 2.0 type of field  and it seems to work well now, i managed to understand the logic after using 2.0 type of field because now it displays correctly which 1.0 type had some "bug".

another "weird bug" is the trace marker shape work for ellipse but not wheel. Or i think it may be an interesting note, because i was stuck wondering why it didn't display the marker  ;D

Anyway these are small matters, important thing is EJS is COOL!!!!


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 26, 2007, 02:33:59 pm
Would you like to upload your xml source so that you can share your simulations with others?


Title: For Educational Purpose, Level Up the have not.
Post by: lookang on July 26, 2007, 06:14:51 pm
Objective
9745 H2 PHYSICS (2008) 8. Oscillations Damped and forced oscillations: resonance (k) describe graphically how the amplitude of a forced oscillation changes with frequency near to the natural frequency of the system, and understand qualitatively the factors which determine the frequency response and sharpness of the resonance.

Make Learning Deep and Sense Making
Resonance
For a forced oscillation, when the driving frequency is equal to the natural frequency of the oscillating system, maximum energy is transferred from the periodic force (driver) to the oscillating system which will vibrate with maximum amplitude. This phenomenon is called resonance.
(http://)
Frequency Response Graph (under different degrees of damping)
The Effect of Damping on Forced Oscillations
When damping is present, it reduces the amplitude (y-axis) of the forced oscillation for all driver frequencies (x-axis) and it causes the maximum amplitude to be reached when the driving frequency is a little less than the natural frequency.
This reduction in amplitude is more significant at the resonance frequency and frequencies close to it, so that we say damping reduces the sharpness of resonance -- that is, the oscillating system responses little (small change in the amplitude) over a wide range of frequencies.

This Interactive Resource was designed by: Wee Loo Kang   


Using Easy Java Simulation by : Francisco Esquembre
 
Thanks to Fu-Kwun Hwang & Francisco Esquembre for their expert advise in (EJS):
Using Forum on EJS:http://www.phy.ntnu.edu.tw/ntnujava/index.php


Title: Re: how to make the text b always appear after the simulation is reset?
Post by: Fu-Kwun Hwang on July 26, 2007, 11:40:25 pm
I duplicate the simulation from your xml source, copy the above message and create a new topic at  Oscillations Damped and forced oscillations by Wee Loo Kang (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=494.0)

Keep up the good work and share more simulations with us!  ::)