NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 22, 2019, 10:56:33 am

"Nothing in life is to be feared, it is only to be understood." ..."Marie Curie 1867-1934, Polish born French Physicist, Twice Nobel Prize Winner- Physics and Chemistry)"

 Pages: [1]   Go Down
 Author Topic: is it possible to eliminate rounding off error in this simulation calculation?  (Read 5737 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member

Offline

Posts: 1792

http://weelookang.blogspot.com

 « Embed this message on: January 25, 2012, 03:45:47 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

Dear Prof Hwang!

is it possible to eliminate rounding off error in this simulation calculation?

http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=2067.msg8920#msg8920

notice the
L1 = 10.416 = 10.42
L2 = 9.393 = 9.38
delta L = 10.33 = 10.3

but 10.42-9.38 =! 10.3 but actually = 10.4
 rippletankkroundingofferrorcansolved.png (116.13 KB, 758x634 - viewed 369 times.) Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3083

 « Embed this message Reply #1 on: January 26, 2012, 08:38:45 am » posted from:,,Satellite Provider

From the attached picture:
L1=10.416
L2=9.383
So L1-L2=1.033
It seems that you round of the above result to 2 significant figures.
So S1P=10.42 , S2P=9.38
and you round off |S1P-S2P} from the above |1.033| value, so you get 1.03

If you want to get 1.04 you should calculate difference from the round-off values instead.

e.g.

double dv;
public float  roundoff(double v){
if(v>0)dv=0.5;
else if(v<0)dv=-0.5;
else dv=0;
return (int)(v*100+dv)/100.;
}

roundoff(L1) will give you 10.42
roundoff(L2)will give you 9.38
roundof(L1-L2)will give you 1.03
roundoff(L1)-roundoff(L2) will give you 1.04

This is an opportunity to teach students about the meaning of significant value (the last digit might be off).

I would not change the above result, but I will ask student why it is off (provide opportunity for student to think about this problem).
It could have more education value if we take the opportunity to invite student to think/learn:
There is always error due to numerical simulation.
And the physics experiment always contain error, too! It is a nature of physics.
 Logged
lookang
Hero Member

Offline

Posts: 1792

http://weelookang.blogspot.com

 « Embed this message Reply #2 on: January 26, 2012, 07:36:28 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i agree!
i will not modify the simulation to have round-off effect.

thanks for the Ejs tip on round off and the greater learning of nature of precision in physics!
 Logged
 Pages: [1]   Go Up
"Nothing in life is to be feared, it is only to be understood." ..."Marie Curie 1867-1934, Polish born French Physicist, Twice Nobel Prize Winner- Physics and Chemistry)"