Cody

# Problem 2909. Approximation of Pi (vector inputs)

Solution 1791340

Submitted on 17 Apr 2019 by David Legrand
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:5; y_correct = [-0.858407346410207 0.474925986923126 -0.325074013076874 0.246354558351698 -0.198089886092747]; answers = pi_approx(n); for i = 1:numel(n) assert(abs(answers(i)-y_correct(i))<(100*eps)) end

y = -0.8584 y = -0.8584 0.4749 y = -0.8584 0.4749 -0.3251 y = -0.8584 0.4749 -0.3251 0.2464 y = -0.8584 0.4749 -0.3251 0.2464 -0.1981

2   Pass
n = 2:2:10; y_correct = [0.474925986923126 0.246354558351698 0.165546477543617 0.124520836517975 0.099753034660390]; answers = pi_approx(n); for i = 1:numel(n) assert(abs(answers(i)-y_correct(i))<(100*eps)) end

y = 0.4749 y = 0.4749 0.2464 y = 0.4749 0.2464 0.1655 y = 0.4749 0.2464 0.1655 0.1245 y = 0.4749 0.2464 0.1655 0.1245 0.0998

3   Pass
n = 5:5:25; y_correct = [-0.198089886092747 0.099753034660390 -0.066592998672151 0.049968846921953 -0.039984031845239]; answers = pi_approx(n); for i = 1:numel(n) assert(abs(answers(i)-y_correct(i))<(100*eps)) end

y = -0.1981 y = -0.1981 0.0998 y = -0.1981 0.0998 -0.0666 y = -0.1981 0.0998 -0.0666 0.0500 y = -0.1981 0.0998 -0.0666 0.0500 -0.0400

4   Pass
n = 10:10:100; y_correct = [0.099753034660390 0.049968846921953 0.033324086890846 0.024996096795960 0.019998000998782 0.016665509660796 0.014284985608559 0.012499511814072 0.011110768228485 0.009999750031239]; answers = pi_approx(n); for i = 1:numel(n) assert(abs(answers(i)-y_correct(i))<(100*eps)) end

y = 0.0998 y = 0.0998 0.0500 y = 0.0998 0.0500 0.0333 y = 0.0998 0.0500 0.0333 0.0250 y = 0.0998 0.0500 0.0333 0.0250 0.0200 y = 0.0998 0.0500 0.0333 0.0250 0.0200 0.0167 y = 0.0998 0.0500 0.0333 0.0250 0.0200 0.0167 0.0143 y = 0.0998 0.0500 0.0333 0.0250 0.0200 0.0167 0.0143 0.0125 y = 0.0998 0.0500 0.0333 0.0250 0.0200 0.0167 0.0143 0.0125 0.0111 y = 0.0998 0.0500 0.0333 0.0250 0.0200 0.0167 0.0143 0.0125 0.0111 0.0100