Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Help Archimedes Method

  1. Feb 6, 2007 #1
    I need to write a program that calculates the value of pi to 10 decimal places by using 'Archimedes Method'.
    Archimedes concluded that:
    n*sin(theta/2) < pi < n*tan(theta/2)

    Basically, I need some help. Anyone got any ideas or any code just to get me started. I'm clueless at the moment.

    Thanks in advance o:)
  2. jcsd
  3. Feb 9, 2007 #2
    Has no1 got any ideas???

  4. Feb 9, 2007 #3
    What you need to do is to find out theta as function of n , if you can find that out , it will be easy for you to do the program.
    Last edited: Feb 9, 2007
  5. Feb 9, 2007 #4
    and if my memory serves me well i think theta=Pi*(n-2)/n
    Last edited: Feb 9, 2007
  6. Feb 11, 2007 #5
    Hey thanks for your reply.

    However, I cannot use pi in my program.

    theta is the angle subtended by any side of the polygon at the circle centre (=360/n degrees)

    I'm kinda at a loss of what to do. I've tried sum code but I I'm not getting anywhere and I'm not even sure what i'm doing.

    Please help.

  7. Feb 13, 2007 #6
    Anyone got any ideas?
  8. Feb 13, 2007 #7


    User Avatar

  9. Feb 13, 2007 #8
    why don't you use Sin&Tan in degree format ?
    then theta=180*(n-2)/n ??
    Last edited: Feb 13, 2007
  10. Feb 13, 2007 #9
    thanks for your replies!!

    I've been at this problem for ages trying but I'm not getting anywhere. Can anyone break this problem down for me in to its core components or provide some code to get me going in the right direction. Really stuck!

    Thanks alot!
  11. Feb 15, 2007 #10
    So . . . Out of the 100 odd views from this forum - there has not been one person capable of programming or shedding some light on this Matlab problem?
  12. Feb 15, 2007 #11
    Try reading http://personal.bgsu.edu/~carother/pi/Pi3a.html . Keep following the links that mention iterative formulas, and then read the simple example. The simple example is what you want to implement in Matlab. You should probably write a detailed comment block explaining your initial guesses for the upper and lower bounds and/or explaining the iterative formulas for the lower and upper bounds, and you should definitely cite the webpage if you find it helpful.
  13. Feb 15, 2007 #12
    What is the problem? Do you not know how to find theta(n) or do you not know how to implement it in Matlab?
  14. Feb 15, 2007 #13
    Before you even start to use Matlab (or any other computing tools) to solve the problem, you should at least have a plan in mind about the approach/method to use.

    You asked about how Matlab can be used to solve the problem; well, tell us something about your plan (a pseudocode or the sort) and we will teach you how to implement that with Matlab.

    Remember, Matlab is not the problem here. The problem, so far, is this: How do you use Archimedes Method to calculate pi.
  15. Feb 18, 2007 #14
    Thanks for your replies

    The guy with the web address . . . I aint got a clue what thats going on about
    I cant follow it at all

    I tried following it . . . wrote some code - its crap
    Code (Text):

    Pm = 1
        for n=1:15
              theta = 360/n;

        x = sin(theta);
        y = tan(theta);
        xn = (x*y)/(x+y);
        Pn = (2^(n+1))*xn;
        pn = (2^n)*x;
        Pn = (2^n)*y;
        pm = sqrt(pn*Pm)
        Pm = (2*pn*Pn)/(pn+Pn)
    what the hell is that? i dunno.

    I thank you lot for your efforts in trying to help but it hasnt really helped me. Maybe if you actually were able to solve the tasks yourselves you would be able to help rather that just putting down what you think would be good ideas without knowing how to solve the problem yourselves.

    Its not as easy as you seem to think. If it is, then prove it.
  16. Feb 18, 2007 #15
    Well, at least you've got something written, which is a start. Here is the outline of some code that I whipped up based on http://personal.bgsu.edu/~carother/pi/Pi3d.html :
    Code (Text):

    % archpi.m
    % Calculates pi by Archimedes' method
    % Reference: http://personal.bgsu.edu/~carother/pi/Pi3a.html

    p = 2*sqrt(2);
    q = 4;

    disp(sprintf('p \t\t q \t\t error'))

    while ?
        disp(sprintf('%1.11f \t %1.11f \t %1.11f',p,q,abs(q-p)))
        nextq = ?;
        p = ?;
        q = ?;

    disp(sprintf('%1.11f \t %1.11f \t %1.11f',p,q,abs(q-p)))
    I didn't remember offhand whether Matlab is case-sensitive with respect to variable names, so I used q instead of P. The question marks indicate that the details of the code for that line are for you to fill in.

    The output of this code, when it is filled out, is:
    Code (Text):

    p        q       error
    2.82842712475    4.00000000000   1.17157287525
    3.06146745892    3.31370849898   0.25224104006
    3.12144515226    3.18259787807   0.06115272582
    3.13654849055    3.15172490743   0.01517641688
    3.14033115695    3.14411838525   0.00378722829
    3.14127725093    3.14222362994   0.00094637901
    3.14151380114    3.14175036917   0.00023656802
    3.14157294037    3.14163208070   0.00005914034
    3.14158772528    3.14160251026   0.00001478498
    3.14159142151    3.14159511775   0.00000369624
    3.14159234557    3.14159326963   0.00000092406
    3.14159257658    3.14159280760   0.00000023101
    3.14159263434    3.14159269209   0.00000005775
    3.14159264878    3.14159266322   0.00000001444
    3.14159265239    3.14159265600   0.00000000361
    3.14159265329    3.14159265419   0.00000000090
    3.14159265351    3.14159265374   0.00000000023
    3.14159265357    3.14159265363   0.00000000006
    As I mentioned in my previous post, if you use this approach, you must at least cite the website, and it would be even better to derive the formulas for p and q.
  17. Feb 19, 2007 #16
    Hey Thanks alot! That was a big help.

    Thanks agan
    Last edited: Feb 19, 2007
  18. Feb 19, 2007 #17
    No problem. :smile: I remember working on similar projects and programs not that long ago and having no idea how to get started, but at the same time I know that I'm not doing you any favors in the long run if I do it all for you. With some practice, it will become easier to read a paper full of confusing formulas, identify the few equations that you need to implement a program, and to figure out the code required to implement it. Most algorithms don't require very much code--in fact, they tend to take much less code than you would expect--but it still takes a lot of thought to figure out what to write.
  19. Feb 19, 2007 #18
    I totally agree :biggrin: Thanks for your help!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matlab Help Archimedes Method