Matlab Help Archimedes Method

In summary: I don't remember what the question marks indicate. Sorry. Anyway, the code calculates pi to 10 decimal places and prints the results.
  • #1
123
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
  • #2
Has no1 got any ideas?

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

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


Thanks alot!
 
  • #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 alot! 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!
 

What is the Archimedes Method in Matlab?

The Archimedes method in Matlab is a numerical method used for approximating the value of pi. It involves inscribing a polygon within a circle and calculating the perimeter of the polygon to approximate the circumference of the circle.

How do I implement the Archimedes Method in Matlab?

To implement the Archimedes Method in Matlab, you will need to define the number of sides of the inscribed polygon, calculate the length of each side, and use a loop to iterate through the calculation of the perimeter. Finally, you can compare the calculated value to the known value of pi to determine the accuracy of the approximation.

What are the advantages of using the Archimedes Method in Matlab?

The Archimedes Method in Matlab is advantageous because it is a simple and easy-to-implement algorithm for approximating pi. It also allows for a degree of control over the accuracy of the approximation by adjusting the number of sides of the inscribed polygon. Additionally, it is a visual and intuitive method, making it helpful for understanding the concept of numerical approximation.

Are there any limitations to the Archimedes Method in Matlab?

One limitation of the Archimedes Method in Matlab is that it can only approximate pi within a certain degree of accuracy. As the number of sides of the inscribed polygon increases, the accuracy of the approximation also increases, but there will always be some degree of error. Additionally, the Archimedes Method may be time-consuming for large numbers of sides, making it less efficient for extremely precise approximations.

How can I improve the accuracy of the Archimedes Method in Matlab?

To improve the accuracy of the Archimedes Method in Matlab, you can increase the number of sides of the inscribed polygon or use a more advanced numerical method. Additionally, you can use the calculated value of pi from one iteration to determine the number of sides for the next iteration, known as the adaptive Archimedes Method. This can lead to a more accurate approximation with fewer iterations.

Suggested for: Matlab Help Archimedes Method

Replies
4
Views
2K
Replies
4
Views
453
Replies
1
Views
803
Replies
5
Views
916
Replies
2
Views
2K
Replies
32
Views
2K
Replies
2
Views
1K
Back
Top