Little math problem(s) January 2019
|
01-28-2019, 09:59 PM
Post: #8
|
|||
|
|||
RE: Little math problem(s) January 2019
Hi: (01-27-2019 02:26 AM)Allen Wrote: Would it be allowed to calculate the answer 1 million times and take the median? This ^ It works perfectly and requires no clever thought or sophistication whatsoever, simply perform N independent calculations (each with a maximum relative error of 20%), then simply output the mean: probabilistically, the error will be reduced by a factor of Sqr(N) and so will tend to zero as N tends to infinity As proof-of-concept, simply run this short HP-71B BASIC code snippet: (Sin(1) can be replaced by any other value or formula) 1 DESTROY ALL @ RANDOMIZE 1 @ T=SIN(1) @ FOR K=1 TO 6 @ N=10^K 2 S=0 @ FOR I=1 TO N @ S=S+T*(.8+.4*RND) @ NEXT I 3 DISP USING "8D,3(2X,Z.6D)";N;S/N;T;ABS(S/N-T) @ NEXT K > RUN N Mean Exact Abs(error) ---------------------------------------------- 10 0.867936 0.841471 0.026465 100 0.832384 0.841471 0.009087 1000 0.838462 0.841471 0.003009 10000 0.840485 0.841471 0.000986 100000 0.841524 0.841471 0.000053 1000000 0.841477 0.841471 0.000006 As can be seen, the error diminishes steadily as N goes from 10 to one million evaluations by a factor of approximately Sqr(10) = 3.16+ as N increases tenfold, and you eventually get about 5 correct digits, a relative error reduction from the initial 0.2 (20%) for a single evaluation to 0.0000006 (0.0006%) for the average of one million evaluations. Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Little math problem(s) January 2019 - pier4r - 01-26-2019, 10:19 PM
RE: Little math problem(s) January 2019 - Allen - 01-27-2019, 02:26 AM
RE: Little math problem(s) January 2019 - Valentin Albillo - 01-28-2019 09:59 PM
RE: Little math problem(s) January 2019 - pier4r - 02-04-2019, 03:15 PM
RE: Little math problem(s) January 2019 - pier4r - 01-27-2019, 10:16 AM
RE: Little math problem(s) January 2019 - Allen - 01-27-2019, 03:28 PM
RE: Little math problem(s) January 2019 - pier4r - 01-27-2019, 04:26 PM
RE: Little math problem(s) January 2019 - Paul Dale - 01-28-2019, 01:53 AM
RE: Little math problem(s) January 2019 - pier4r - 01-28-2019, 12:12 PM
RE: Little math problem(s) January 2019 - Thomas Klemm - 01-28-2019, 11:03 PM
|
User(s) browsing this thread: