Created
February 24, 2014 04:21
-
-
Save dkellycollins/9181926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Sum | |
{ | |
class Program | |
{ | |
//Estimates the perimeter of a circle of radius 1 using Archimededes formulas | |
static void Main(string[] args) | |
{ | |
int n = 96; //n-polygon to estimate with. | |
double r = 1; //radius of the circle. | |
double A = 1/Math.Sqrt(3); //value of A1. | |
double C = 2/Math.Sqrt(3); //value of C1. | |
int k = (int)Math.Log(n, 2); | |
for (int i = 2; i < k; i++) | |
{ | |
A = A / (1.0 + C); | |
C = Math.Sqrt((A * A) + 1.0); | |
} | |
double estimate = n * 2 * A; | |
double actual = 2 * Math.PI * r; | |
Console.WriteLine("n = {0}, A = {1}, C = {2}", n, A, C); | |
Console.WriteLine("Estimate = {0}", estimate); | |
Console.WriteLine("Actual = {0}", actual); | |
Console.WriteLine("Difference = {0}", estimate - actual); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment