|
-
Aug 12th, 2002, 07:30 PM
#1
Thread Starter
New Member
oops! still stuck on my loop calculation, explained the question
/* Hi with out sounding total thick! Here is the sum by Archimedes
i am trying to work out ,n = number of sides in a polygon.
He realized that the perimeter of a regular polygon of n sides inscribed
in a circle is smaller than the circumference of that circle and that
the perimeter of a regular polygon of n sides circumscribed around a
circle is greater than the circumference of that circle.
As n approaches infinity, the two perimeters approach the circumference,
In fact, one can think of a circle as a regular polygon with infinitely
many sides.
Using simple trigonometry, he showed that the perimeter of the
circumscribed polygon is 2nrsin(theta/2) and that the inscribed polygon
is 2nrtan (theta/2), where 0 is the angle subtended by any side of the
polygon at the centre (=360/n degrees). He concluded
n sin theta < PI < n tan theta
2 2
Now i have not do maths for 31 years now but i take this sum
to be the same as:
n sin 180 is less than PI and that PI is still less than n tan
I need to know how many sides for a polygon are needed to achieve this accuracy
So I want the computer to keep increasing the number of sides to achive
This accuracy
I need a loop to increase my sides by ++ till they reach this accuracy
The code I was given I can not get to won’t work
for (sides = 4; (Math.sin(Math.toRadians (sides)) <= Math.PI) + (Math.tan(Math.toRadians(sides)) >= Math.PI); sides++);
so I am still not getting any beauty sleep
*/
import java.math.*;
import java.io.*;
class ged1looptry
{
public static void main(String [] args)throws IOException
{
double sides = 4;
double n = (180/ sides);
double s = Math.sin(Math.toRadians(n));
double t = Math.tan (Math.toRadians(n));
double PI = 3.14592653589;
/*for (sides = 4; (Math.sin(Math.toRadians (sides)) <= Math.PI) + (Math.tan(Math.toRadians(sides)) >= Math.PI); sides++);*/
System.out.println("Sin ="+ s +" <=" + PI+ "<="+t );
}
}
// or am i working the maths wrong as well
-
Aug 12th, 2002, 07:40 PM
#2
Thread Starter
New Member
sorry the line
is 2nrtan (theta/2), where 0 is the angle subtended by any side of the
should have read , where theta is the angle subtended by any side of the
and not! 0 as i forgot this won't take the theta sign
-
Aug 12th, 2002, 07:47 PM
#3
Thread Starter
New Member
god i'm sorry my message looks all cocked up, i found another mistake
Using simple trigonometry, he showed that the perimeter of the
circumscribed polygon is 2nrsin(theta/2) and that the inscribed polygon
is 2nrtan (theta/2), where 0 is the angle subtended by any side of the
polygon at the centre (=360/n degrees). He concluded
n sin theta < PI < n tan theta
...........2........................2
this last line is correct now theta divided by 2
i never expected the 2 to move over when posted
goes to show how much this is doing my head in.
Last edited by ged; Aug 12th, 2002 at 07:52 PM.
-
Aug 13th, 2002, 05:24 PM
#4
Hyperactive Member
He he. Maybe you should think about the sum a little clearer. Archimedes PROVED that: n sin (Theta) <= PI <= n tan (Theta) for all n. Now, theoretically this theorem should hold as lim(n -> infinity). Now, what I think you're asking is that a computer run until it has a number of sides to satisfy the equation that LHS = PI = RHS. The code at the bottom of the page will run until 10000, displaying all the values for you to see. I'm sorry, but I made a mistake in the prevoius code that I gave you. I forgot that you need to append a .0 to a number when dividing, otherwise it returns an integer value instead of a double.
Anyway, if you take the limit then you can actually prove this inequality. Anyhow, any value of n will satisfy the equation. What you obviously want to know is how many sides you should take for the circumferences to be sufficiently *small*. If sides is taken as 10000, then the value is correct for up to 6 decimal places.
Code:
int sides;
double theta,tan,sin;
for (sides = 4; (((sides * Math.sin(Math.toRadians(180.0/sides)))) <= Math.PI) || (((sides * Math.tan(Math.toRadians(180.0/sides)))) >= Math.PI);sides++)
{
theta = 180.0 / sides;
sin = Math.sin(Math.toRadians(theta));
tan = Math.tan(Math.toRadians(theta));
System.out.println(sides + " * sin("+theta+") = " + (sides * sin) + " <= " + Math.PI + " <= " + sides + " * tan("+theta+") = " + (sides * tan));
if (sides == 10000) break;
}
theta = 180.0/sides;
sin = Math.sin(Math.toRadians(theta));
tan = Math.tan(Math.toRadians(theta));
System.out.println(sides + " * sin("+theta+") = " + (sides * sin) + " <= " + Math.PI + " <= " + sides + " * tan("+theta+") = " + (sides * tan));
Hope that helps.
-
Aug 13th, 2002, 05:30 PM
#5
Hyperactive Member
BTW. Just reading a previous post.
49 * tan (180/49) = 3.1459043769946550994301704124159
Pi = 3.1415926535897932384626433832795
So the tan at 49 sides is still more than pi
-
Aug 13th, 2002, 06:24 PM
#6
Thread Starter
New Member
Well what can i say, i would have to write a loop to say thank
you a million times.
i have ran your code and it works out great, looking back now i will have to learn more maths before i attempt something like that again,
thank you for the 1000,001 time
ged
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|