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

Easy Java Simulations (2001- ) => Questions related to EJS => Topic started by: lookang on March 22, 2010, 03:37:19 pm



Title: histogram how can i dont count values =0 ?
Post by: lookang on March 22, 2010, 03:37:19 pm
Hi prof,
histogram how can i dont count values =0 ?

http://www.um.es/fem/EjsWiki/Main/ElementsHistogram



Title: Re: histogram how can i dont count values =0 ?
Post by: Fu-Kwun Hwang on March 22, 2010, 04:34:50 pm
Have you tried to assign a variable to "Enabled", then set it to false if you want to disable adding data to histogram.
Set it to true when you want to add values to histogram.


Title: Re: histogram how can i dont count values =0 ?
Post by: lookang on March 22, 2010, 06:26:16 pm
sori was in a hurry to post the laptop battery dying so i didn't explain clearly my problem.

Have you tried to assign a variable to "Enabled", then set it to false if you want to disable adding data to histogram.
Set it to true when you want to add values to histogram.
i did but it didn't work the way i wanted.

the problem i am trying to solve is this.
(http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1487.0;attach=1763;image)
i have n = 20
use j instead of i
i have speed[j] = 20 numbers correct and required but i also have 180 zero values because i declared n = nmax and nmax = 200
so the speed[j] actually has 20 numbers spread around 500 but 180 values =0
thus the histogram is displaying a very high probability about 0.8 for the bin = 0 to 50

i want to count only the n = 20, speed[0] , speed[1], speed[2],......speed[19] values in the histogram.

i been thinking and thinking but i can't formulate the codes. and was hoping for an easy selectable option in the Ejs histogram list of field.

chance for tips or example codes for me to do some trial and error?

i tried to do but it makes the applet cannot display the particles.

sometime like

Code:
for (int i=0; iif (speed[i] > 0.1) {
histogramspeed[i]= speed[i];
  histogramn = histogramn+1;
}

Thanks for your help! ;D


Title: Re: histogram how can i dont count values =0 ?
Post by: lookang on March 22, 2010, 08:33:09 pm
i think i got it!!
histogram

use j instead of i
if (speed[j]==1) {
  histogram=false;
}
else {
  histogram = true;
}
no worries!


Title: Re: histogram how can i dont count values =0 ?
Post by: lookang on March 22, 2010, 09:10:50 pm
i am not sure that the code work but i change the initial value of the number of particles n = 200 and the problem seems to disappear.

will ask when need again :)


Title: Re: histogram how can i dont count values =0 ?
Post by: Fu-Kwun Hwang on March 22, 2010, 09:18:15 pm
I am sorry that I did not really fully understood what was your problem.
But I am glad to hear that the problem seems to be solved!


Title: Re: histogram how can i dont count values =0 ?
Post by: lookang on March 22, 2010, 09:33:56 pm
when i use n=200, beautiful see picture(http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1487.0;attach=1766;image)
.

the problem appears when i use n any number less than 200 because i think the array is [n]
so speed[j] has 200 values which is pipe into the histogram despite the slider value at n = 21 for example.

see the picture (http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=1487.0;attach=1767;image)

haiz
i think i didn't solve it :)

any tips!
i attached the source in case u need to understand the problem.  ;D


Title: Re: histogram how can i dont count values =0 ?
Post by: Fu-Kwun Hwang on March 22, 2010, 10:40:46 pm
The histogram find it's number of element from it's own definition.
It was define as speed[nmax] , so the element always use nmax as the number of element for speed.
When you drag slider to change value of n, it does not change the size of the speed array.

So I add
Code:
if(n at the last line in initlalize page to fix it.

I also un-comment the following at "Brownian" page under "Fixed relations".
Code:
//if(!accumulateData) _view.speedHistogram.clear();
The above code will cause error , when there is no data in the histogram (nothing to be clear).

Please check out the attached xml file.


Title: Re: histogram how can i dont count values =0 ?
Post by: lookang on March 22, 2010, 10:59:31 pm
 
Code:
if(n <  nmax)speed=new double[n];

clever! thx! i would have never been able to dream up this code, i learn something new again!

The histogram find it's number of element from it's own definition.
It was define as speed[nmax] , so the element always use nmax as the number of element for speed.
When you drag slider to change value of n, it does not change the size of the speed array.

So I add
Code:
if(n <  nmax)speed=new double[n];
at the last line in initlalize page to fix it.

I also un-comment the following at "Brownian" page under "Fixed relations".
Code:
//if(!accumulateData) _view.speedHistogram.clear();
The above code will cause error , when there is no data in the histogram (nothing to be clear).

Please check out the attached xml file.


i also added the tip on http://www.um.es/fem/EjsWiki/Main/ElementsHistogram

If the simulation uses [n] array together with a slider for [n], initialize page may need to add code” if(n < nmax)speedarray=new double[n]; “ for histogram to display array correctly as [n]. Check out http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1487.msg5607#msg5607  for in-depth discussion.