www.delorie.com/gnu/docs/calc/calc_63.html search
GNU Emacs Calc 2.02 Manual

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

### 3.7.29 List Tutorial Exercise 11

The circle of unit radius consists of those points (x,y) for which x^2 + y^2 < 1. We start by generating a vector of x^2 and a vector of y^2.

We can make this go a bit faster by using the v . and t . commands.

 ```2: [2., 2., ..., 2.] 2: [2., 2., ..., 2.] 1: [2., 2., ..., 2.] 1: [1.16, 1.98, ..., 0.81] . . v . t . 2. v b 100 RET RET V M k r ```
 ```2: [2., 2., ..., 2.] 1: [0.026, 0.96, ..., 0.036] 1: [0.026, 0.96, ..., 0.036] 2: [0.53, 0.81, ..., 0.094] . . 1 - 2 V M ^ TAB V M k r 1 - 2 V M ^ ```

Now we sum the x^2 and y^2 values, compare with 1 to get a vector of 1/0 truth values, then sum the truth values.

 ```1: [0.56, 1.78, ..., 0.13] 1: [1, 0, ..., 1] 1: 84 . . . + 1 V M a < V R + ```

The ratio 84/100 should approximate the ratio pi/4.

 ```1: 0.84 1: 3.36 2: 3.36 1: 1.0695 . . 1: 3.14159 . 100 / 4 * P / ```

Our estimate, 3.36, is off by about 7%. We could get a better estimate by taking more points (say, 1000), but it's clear that this method is not very efficient!

(Naturally, since this example uses random numbers your own answer will be slightly different from the one shown here!)

If you typed v . and t . before, type them again to return to full-sized display of vectors.

 webmaster delorie software   privacy Copyright © 2003   by The Free Software Foundation Updated Jun 2003
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}