View Full Version : Matlab Help
strokebow
Feb6-07, 08:28 AM
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:)
strokebow
Feb9-07, 09:28 AM
Has no1 got any ideas???
Thanks
ziad1985
Feb9-07, 09:59 AM
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.
ziad1985
Feb9-07, 10:06 AM
and if my memory serves me well i think theta=Pi*(n-2)/n
strokebow
Feb11-07, 08:35 AM
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
strokebow
Feb13-07, 06:36 AM
Anyone got any ideas?
Why not just implement, eg., this: http://www.escape.com/~paulg53/math/pi/archimedes/index.html
ziad1985
Feb13-07, 07:57 AM
why don't you use Sin&Tan in degree format ?
then theta=180*(n-2)/n ??
strokebow
Feb13-07, 03:39 PM
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!
strokebow
Feb15-07, 06:52 AM
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?
las3rjock
Feb15-07, 03:58 PM
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.
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?
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.
strokebow
Feb18-07, 12:15 PM
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
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.
las3rjock
Feb18-07, 01:27 PM
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 :
% 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:
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.
strokebow
Feb19-07, 07:22 AM
Hey Thanks alot! That was a big help.
Thanks agan
las3rjock
Feb19-07, 09:41 AM
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.
strokebow
Feb19-07, 01:32 PM
I totally agree :biggrin: Thanks for your help!
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.