Cody

# Problem 2908. Approximation of Pi

Solution 2044258

Submitted on 3 Dec 2019 by Michal Florek
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
n = 1; y_correct = -0.858407346410207; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 a = 1 y = -0.8584

2   Pass
n = 2; y_correct = 0.474925986923126; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 a = 0.6667 y = 0.4749

3   Pass
n = 4; y_correct = 0.246354558351698; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 a = 0.7238 y = 0.2464

4   Pass
n = 7; y_correct = -0.142145830148691; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 a = 0.8209 y = -0.1421

5   Pass
n = 10; y_correct = 0.099753034660390; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 a = 0.7605 y = 0.0998

6   Pass
n = 14; y_correct = 0.071338035810608; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 a = 0.7676 y = 0.0713

7   Pass
n = 17; y_correct = -0.058772861819756; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 a = 0.8001 y = -0.0588

8   Pass
n = 20; y_correct = 0.049968846921953; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Column 19 0.0270 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 20 0.0270 -0.0256 a = 0.7729 y = 0.0500

9   Pass
n = 25; y_correct = -0.039984031845239; assert(abs(pi_approx(n)-y_correct)<(100*eps))

A = 1 A = 1.0000 -0.3333 A = 1.0000 -0.3333 0.2000 A = 1.0000 -0.3333 0.2000 -0.1429 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 A = 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Column 19 0.0270 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 20 0.0270 -0.0256 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 21 0.0270 -0.0256 0.0244 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 22 0.0270 -0.0256 0.0244 -0.0233 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 23 0.0270 -0.0256 0.0244 -0.0233 0.0222 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 24 0.0270 -0.0256 0.0244 -0.0233 0.0222 -0.0213 A = Columns 1 through 18 1.0000 -0.3333 0.2000 -0.1429 0.1111 -0.0909 0.0769 -0.0667 0.0588 -0.0526 0.0476 -0.0435 0.0400 -0.0370 0.0345 -0.0323 0.0303 -0.0286 Columns 19 through 25 0.0270 -0.0256 0.0244 -0.0233 0.0222 -0.0213 0.0204 a = 0.7954 y = -0.0400