NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
June 01, 2020, 03:52:32 am
 Welcome, Guest. Please login or register.Did you miss your activation email? 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length

 Home Help Search Login Register
There is a better way to do it; find it. ..."Thomas Edison(1847-1931, American inventor, 1093 patients)"

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

Offline

Posts: 1796

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 380 times.) Logged
Fu-Kwun Hwang
Hero Member

Offline

Posts: 3085

 « 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: 1796

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
There is a better way to do it; find it. ..."Thomas Edison(1847-1931, American inventor, 1093 patients)"