Calculating Pi with Archimedes Method in Matlab

Click For Summary

Discussion Overview

The discussion revolves around implementing Archimedes' method for calculating the value of pi in Matlab. Participants seek assistance with programming challenges, theoretical understanding, and specific coding issues related to the method.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses a need for help in writing a program to calculate pi using Archimedes' method, specifically mentioning the inequalities involving sine and tangent.
  • Another suggests finding theta as a function of n to facilitate the programming task.
  • A participant proposes that theta can be calculated as (360/n) degrees, while another suggests using degrees in the sine and tangent functions.
  • Several participants share code snippets and outline approaches, but there is uncertainty about the correctness and effectiveness of the provided solutions.
  • One participant expresses frustration over the lack of concrete help from others, questioning the ability of the community to assist with the programming problem.
  • A later reply provides a code outline based on a referenced webpage, indicating that the details need to be filled in by the original poster.
  • Another participant emphasizes the importance of having a plan before implementing the code in Matlab, suggesting that understanding the method is crucial.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to implement Archimedes' method in Matlab. There are multiple suggestions and some disagreement on how to proceed, indicating that the discussion remains unresolved.

Contextual Notes

Some participants express confusion over the provided resources and code examples, highlighting limitations in understanding the iterative formulas and the implementation process in Matlab.

Who May Find This Useful

This discussion may be useful for individuals interested in numerical methods for calculating pi, programming in Matlab, or those seeking to understand Archimedes' method in a computational context.

strokebow
Messages
122
Reaction score
0
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:)
 
Physics news on Phys.org
Has no1 got any ideas?

Thanks
 
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:
and if my memory serves me well i think theta=Pi*(n-2)/n
 
Last edited:
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.

Thanks
 
Anyone got any ideas?
 
why don't you use Sin&Tan in degree format ?
then theta=180*(n-2)/n ??
 
Last edited:
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 into its core components or provide some code to get me going in the right direction. Really stuck!


Thanks a lot!
 
  • #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?
 
  • #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.
 
  • #12
strokebow said:
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?

What is the problem? Do you not know how to find theta(n) or do you not know how to implement it in Matlab?
 
  • #13
strokebow said:
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?

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.
 
  • #14
Thanks for your replies

The guy with the web address . . . I aint got a clue what that's going on about
I can't follow it at all

I tried following it . . . wrote some code - its crap
Code:
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)
    end

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.
 
  • #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:
% 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 = ?;
end

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:
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.
 
  • #16
Hey Thanks a lot! That was a big help.

Thanks agan
 
Last edited:
  • #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.
 
  • #18
I totally agree :biggrin: Thanks for your help!
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
8K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K