NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 21, 2017, 03:41:31 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  
To live close to great minds is the best kind of education. ..."John Buchan (1875~1940 Scotticsh historian, Governor General of Canada)"
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: a bug i don't understand why it is happening something about errors when 0.2 0.8  (Read 8020 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
on: July 15, 2009, 03:54:10 pm » posted from:Singapore,,Singapore

a bug i don't understand why it is happening something about errors when p = -0.2, -0.8, -1.2, -1.8.

the numbers for q and other calculation become wrong, it should be infinity but it shows a large number.

did i code it wrongly?

thx!


* buglen.PNG (72.41 KB, 1024x768 - viewed 284 times.)

* buglen01.PNG (51.45 KB, 1024x768 - viewed 280 times.)

*** There are 2 more attached files. You need to login to acces it!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #1 on: July 16, 2009, 08:00:49 am » posted from:SINGAPORE,SINGAPORE,SINGAPORE

fixed relationship i have a line of code like this:

if ( (p/f==-1&&p<0&&f>0)||(p/f==1&&p>0&&f>0) ) {

s_mom2 = "When Object distance, u = f, use by spotlight when projecting parallel beam of light";
}


the rest of the times it seems p = -f = 0.4, 0.6 1.0, 1.4,1.6,2.0 works  it works for p/f==-1

but when p = -f = -0.2, -0.8, -1.2, -1.8, it fails. It is very strange so i being thinking and thinking but i thought i bounce it off this forum!
thx!
« Last Edit: July 16, 2009, 09:44:49 am by lookang » Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: July 16, 2009, 01:03:38 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i tried using the field to enter the value again, and the bug is problem solved.

i wonder if it is due to
1. the value stored in p = 0.20000000000001 instead of 0.2 exactly is occuring
2. the condition to check maybe i change it to be less strict like 

if ( (p/f<-0.95&&p/f>-1.05&&p<0&&f>0)||(p/f<1.05&&p/f>0.95&&p>0&&f>0) ) {

maybe that will solved the bug problem?
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #3 on: July 16, 2009, 04:28:16 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

continue to work at home later


*** There are 1 more attached files. You need to login to acces it!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #4 on: July 16, 2009, 06:46:55 pm » posted from:Taipei,T\'ai-pei,Taiwan

I am sorry that I was out of town for a few days.

There is finite number of memory storage so there is no way to represent infinite number of all values.
For "double" defined in java/ejs, it use 8 byte to represent a number.
And the maximum number can be represented is about 10138 , there is no way to stored infinite number of different values.
The maximum value is defined as Double.POSITIVE_INFINITY / Doublle.NEGATIVE_INFINITY

For real world problem, if the distance is 100 or 1000. times larger than focus length, it can almost be treated as infinity (the error is too small to be neglected).

Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #5 on: July 17, 2009, 03:57:01 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i managed to re-code the logic of showing the text scaffolds and picture. One problem solved.

It seems there is a bug i can't work around it.

Only for p = -1.8 , f = 1.8, a strange drawing appears.
The rest of the values seems to work well.

any suggestion how to make the bug disappear?

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
  • Please feel free to post your ideas about how to use the simulation for better teaching and learning.
  • Post questions to be asked to help students to think, to explore.
  • Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!


* buglen02.PNG (58.13 KB, 1024x768 - viewed 396 times.)

*** There are 1 more attached files. You need to login to acces it!
« Last Edit: July 17, 2009, 04:02:43 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #6 on: July 17, 2009, 04:52:07 pm » posted from:Taipei,T\'ai-pei,Taiwan

You have the following equation in "Fixed relation" page:
q=f*p/(f+s*p);

It will produce run time error when  f+s*p=0;

You should have check
if(Math.abs(f+s*p)<1.e-6){// or whatever small value which is enough for your case
 q=
}else q=f*p/(f+s*p);
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #7 on: July 17, 2009, 11:17:57 pm » posted from:,,Satellite Provider

ic, good idea.

i did a little more investigation, i think i know the reason for the "bug".

I have a feeling about the "bug" when the values for p and f are not exactly as they seems.
for example p = 1.8, but the computer instead stored it as 1.80000000000000000000001

so i constructed a code

Code:
if(f>0)dv1=0.5; // trying to solve bug of f = 1.8, p = 1.8, lines are drawn in wrong, should be invisible
 else if(f<0)dv1=-0.5;
 else dv1=0;
//f = ((int)(f*100000+dv))/100000.;
f = (int)(f*10+dv1)/10.;

if(p>0)dv2=0.5; // trying to solve bug of f = 1.8, p = 1.8, lines are drawn in wrong, should be invisible
 else if(p<0)dv2=-0.5;
 else dv2=0;
//f = ((int)(f*100000+dv))/100000.;
p = (int)(p*10+dv2)/10.;

to put on the left (this is important the sequence) of
Code:
q=f*p/(f+s*p);

the idea i think is to force the computer to store p = 1.8 instead of 1.80000000000000000000001
and sub into the equation, q=f*p/(f+s*p);

the slider bars default may have caused the 1.8000000000001 i believe.

i think it is ok now! thanks for help and ideas Smiley

i will find out more bugs to overcome, still can do more : Grin
« Last Edit: July 17, 2009, 11:31:42 pm by lookang » Logged
Pages: [1]   Go Up
  Print  
To live close to great minds is the best kind of education. ..."John Buchan (1875~1940 Scotticsh historian, Governor General of Canada)"
 
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.053 seconds with 22 queries.since 2011/06/15