Download Oric-1 Manual - Defence Force
Transcript
-4 - A -+ - 4 i 4 i c+ P li Ic rzi C --i --i Ir? I -i ri Lc i- Chapter 6 Number crunching discovered a way of calculating TI. n is an irrational number; in other words, it can never be calculated to a finite number of decimal places. Leibnitz discovered that this sequence approached closer and closer to the true value. n 2 4(1-+++--f++. . . .)etc. You should be able to see a regular pattern in the fractions. ORIC loves patterns, as they can ble put in loops. I f you were to try to calcul ate the above form u l a with pencil and paper it would take you a long time , even u P to - l/9. - all the worse wh.en you realize that the answer isn’t close enoug h until you’ ve looped several hundred times. Poor Leibnitz, but lucky you! Try this program. 5 10 20 30 40 50 60 70 REM *** SLOW PI *** CLS DEF FNA(N) = (- l/N + l/(N + 2)) FOR X = 3 TO 10003 STEP 4 S = S + FNA(X) APPROX = 4*(1+S) PRINT APPROX NEXTX Line 20 defines a function, A, containing a variable N. This saves having a cumbersome line later. FNA actually calculates the series and is called at line 30. The loop goes up in steps of 4, starting with 3, so X is 3,7,11,15 etc. This makes correct increments and the result is printed at line 50. If you RUN the program, Oric will print a result for TI that gets closer and closer to the actual result. Compare it with 3.1416 and you will see that it’s not the fastest way to calculate n, even with ORIC. To find n rather more quickly, simply type ri - PRINT PI eFi - ri - This will give you an accurate value of 71 to several places o f decimals, as PI is stored as a constant by ORIC. Remember that this means you cannot choose PI as a variable name, or indeed any word beginning with PI, such as PIG = 8 or PIPES = 78, because PI is a reserved word. ii 65 -i - c-