version 1.20.0.0 (3.58 MB) by
Bill McKeeman

Archimedes wrote 3 1/7 > pi > 3 10/71. This is how he did it.

**Editor's Note:** This file was selected as MATLAB Central Pick of the Week

Before there was floating point, or a way to write zero, or algebraic notation, Archimedes bounded the value of pi by estimating the perimeter of regular polygons inside and outside the circle. His computation is repeated and explained here using MATLAB.

Bill McKeeman (2021). The Computation of Pi by Archimedes (https://www.mathworks.com/matlabcentral/fileexchange/29504-the-computation-of-pi-by-archimedes), MATLAB Central File Exchange. Retrieved .

Created with
R2016a

Compatible with any release

**Inspired by:**
Variable Precision Integer Arithmetic, Fractions Toolbox

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

Bill McKeemanI withdraw my request for removal. After 20 minutes the correct presentation finally showed up on my screen. I guess everything is OK. /s/ Bill McKeeman

Bill McKeemanAs the author, I request this submission be removed. It no longer works due to changes in MATLAB. /s/ Bill McKeeman

Bill McKeemanThank you danf. I think your change should be incorporated in the code. I can no longer do this, so MathWorks will have to intervene.

danfAm I the only one? but this code is failing.

----------------------------------------

version= 2015B

error= Assignment between unlike types is not allowed.

Error in ComputationOfPiByArchimedes (line 222)

cf(end+1) = r;

I am running in "run and advance" mode.

The reason is that cf is vpi and r is a vpi (by propagation). But on the 15th or 16th iteration r is assigned 1 (r=1).

So I changed to r= vpi(1) and it corrected the problem.

Still I wonder. After all, this is a pick of the week, so it was working.

When did it break?

Zachary DanzigerDerek O'ConnorThis is a lovely piece of work and is a credit to the author Bill McKeeman. This is a great example to use when explaining successive approximations and the difference between rational and floating point numbers.

With reference to Bill's and John D'Errico's comments I would like to make two points:

(1).

Unfortunately Mathworks's websites are so far behind the times that it makes publishing anything that includes mathematics very difficult, and anything such as Bill's work, nearly impossible, as he notes in his 20 Jun 2011 comment.

Mathworks should look at how Stack Exchange handles typesetting text, mathematics, code, and diagrams. Here are examples of my posts to Math Stack Exchange:

Square Root: http://math.stackexchange.com/questions/90435/

Sign of Perm: http://math.stackexchange.com/questions/65923/

Boolean Inverses: http://math.stackexchange.com/q/111357/14701

The last example has a link to Mathworks's Answers

http://www.mathworks.co.uk/matlabcentral/answers/16192-inversion-of-a-boolean-matrix

so you can can switch from Stack Exchange to Mathworks and back, to see the stark contrast.

(2).

I agree with John's two uses of FEX, but I would add a third: to see BAD code. As John knows well, such code can lead to very lively discussions indeed. These discussions can be very fruitful for all concerned, except perhaps the writer of the code.

It is for this third reason that I deplore Mathworks's policy of allowing code submissions and the discussion surrounding the submission, to be deleted by the author of the code. If authors knew that they could not delete their code, then they might be more careful about what they submit.

Ben PetschelVery nice work.

Bill McKeemanMathWorks just fixed the bug that was messing up the text. So, I'll leave the entry where it is. Thanks Matthew.

Bill McKeemanUnfortunately, MathWorks has made changes in the published form of this submission which make it harder to read. I plan to delete the entry in a few days.

Nicolas CusseauJohn D'ErricoThere are two uses for the File Exchange that I love. One is to provide high quality code. The second is to teach others about some interesting part of mathematics and hopefully, write it using well written MATLAB code. This submission eminently qualifies. You can read it and learn something from what Bill has done.