Cody

# Problem 2909. Approximation of Pi (vector inputs)

Solution 1941126

Submitted on 18 Sep 2019
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   Fail
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 = 2.141592653589793 y = 2.141592653589793 3.474925986923127 y = 2.141592653589793 3.474925986923127 2.941592653589793 y = 2.141592653589793 3.474925986923127 2.941592653589793 3.284449796446936 y = 2.141592653589793 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682

Assertion failed.

2   Fail
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 = 3.474925986923127 y = 3.474925986923127 2.941592653589793 y = 3.474925986923127 2.941592653589793 3.284449796446936 y = 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682 y = 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682 3.232501744498884 y = 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682 3.232501744498884 3.064669576666716 y = 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 y = 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 y = 3.474925986923127 2.941592653589793 3.284449796446936 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162

Assertion failed.

3   Fail
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 = 3.030481542478682 y = 3.030481542478682 3.232501744498884 y = 3.030481542478682 3.232501744498884 3.064669576666716 y = 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 y = 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 y = 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 y = 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 y = 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 y = 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Column 10 3.178629690626830 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 11 3.178629690626830 3.107109894969104 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 12 3.178629690626830 3.107109894969104 3.173850718105922 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 13 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 14 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 15 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 16 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 3.167233679230819 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 17 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 3.167233679230819 3.117202409687354 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 18 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 18 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 Column 19 3.119370431367571 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 18 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 Columns 19 through 20 3.119370431367571 3.162869249334474 y = Columns 1 through 9 3.030481542478682 3.232501744498884 3.064669576666716 3.208259320256460 3.082769124178029 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 Columns 10 through 18 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 Columns 19 through 21 3.119370431367571 3.162869249334474 3.121184490324487

Assertion failed.

4   Fail
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 = 3.194224232537162 y = 3.194224232537162 3.093973605970746 y = 3.194224232537162 3.093973605970746 3.185070914459359 y = 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 y = 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 y = 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 y = 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 y = 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 y = 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Column 10 3.114565626562766 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 11 3.114565626562766 3.167233679230819 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 12 3.114565626562766 3.167233679230819 3.117202409687354 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 13 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 14 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 15 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 16 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 17 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Column 19 3.159774471771611 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 20 3.159774471771611 3.124048793940670 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 21 3.159774471771611 3.124048793940670 3.158541806132166 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 22 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 23 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 3.157465669462809 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 24 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 3.157465669462809 3.126208038205178 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 25 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 3.157465669462809 3.126208038205178 3.156518026724121 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 26 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 3.157465669462809 3.126208038205178 3.156518026724121 3.127099899966605 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 27 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 3.157465669462809 3.126208038205178 3.156518026724121 3.127099899966605 3.155677160632047 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 27 3.159774471771611 3.124048793940670 3.158541806132166 3.125199210966843 3.157465669462809 3.126208038205178 3.156518026724121 3.127099899966605 3.155677160632047 Column 28 3.127894023452807 y = Columns 1 through 9 3.194224232537162 3.093973605970746 3.185070914459359 3.101592653589793 3.178629690626830 3.107109894969104 3.173850718105922 3.111289623286763 3.170164082161222 Columns 10 through 18 3.114565626562766 3.167233679230819 3.117202409687354 3.164848467543282 3.119370431367571 3.162869249334474 3.121184490324487 3.161200496727048 3.122724729061491 Columns 19 through 27 ...

Assertion failed.