Cody

# Problem 2909. Approximation of Pi (vector inputs)

Solution 1687607

Submitted on 6 Dec 2018 by Martin C.
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

ap = [] y = 0 y = 1 ap = 1 y = 0 y = 1 y = 0.6667 ap = 1.0000 0.6667 y = 0 y = 1 y = 0.6667 y = 0.8667 ap = 1.0000 0.6667 0.8667 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 ap = 1.0000 0.6667 0.8667 0.7238 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 ap = 1.0000 0.6667 0.8667 0.7238 0.8349 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

ap = [] y = 0 y = 1 y = 0.6667 ap = 0.6667 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 ap = 0.6667 0.7238 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 ap = 0.6667 0.7238 0.7440 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 ap = 0.6667 0.7238 0.7440 0.7543 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 ap = 0.6667 0.7238 0.7440 0.7543 0.7605 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

ap = [] y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 ap = 0.8349 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 ap = 0.8349 0.7605 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 ap = 0.8349 0.7605 0.8020 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 ap = 0.8349 0.7605 0.8020 0.7729 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 ap = 0.8349 0.7605 0.8020 0.7729 0.7954 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

ap = [] y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 ap = 0.7605 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 ap = 0.7605 0.7729 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 ap = 0.7605 0.7729 0.7771 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 ap = 0.7605 0.7729 0.7771 0.7791 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 y = 0.7915 y = 0.7794 y = 0.7912 y = 0.7797 y = 0.7910 y = 0.7800 y = 0.7907 y = 0.7802 y = 0.7905 y = 0.7804 ap = 0.7605 0.7729 0.7771 0.7791 0.7804 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 y = 0.7915 y = 0.7794 y = 0.7912 y = 0.7797 y = 0.7910 y = 0.7800 y = 0.7907 y = 0.7802 y = 0.7905 y = 0.7804 y = 0.7903 y = 0.7806 y = 0.7901 y = 0.7808 y = 0.7899 y = 0.7809 y = 0.7898 y = 0.7811 y = 0.7896 y = 0.7812 ap = 0.7605 0.7729 0.7771 0.7791 0.7804 0.7812 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 y = 0.7915 y = 0.7794 y = 0.7912 y = 0.7797 y = 0.7910 y = 0.7800 y = 0.7907 y = 0.7802 y = 0.7905 y = 0.7804 y = 0.7903 y = 0.7806 y = 0.7901 y = 0.7808 y = 0.7899 y = 0.7809 y = 0.7898 y = 0.7811 y = 0.7896 y = 0.7812 y = 0.7895 y = 0.7814 y = 0.7894 y = 0.7815 y = 0.7892 y = 0.7816 y = 0.7891 y = 0.7817 y = 0.7890 y = 0.7818 ap = 0.7605 0.7729 0.7771 0.7791 0.7804 0.7812 0.7818 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 y = 0.7915 y = 0.7794 y = 0.7912 y = 0.7797 y = 0.7910 y = 0.7800 y = 0.7907 y = 0.7802 y = 0.7905 y = 0.7804 y = 0.7903 y = 0.7806 y = 0.7901 y = 0.7808 y = 0.7899 y = 0.7809 y = 0.7898 y = 0.7811 y = 0.7896 y = 0.7812 y = 0.7895 y = 0.7814 y = 0.7894 y = 0.7815 y = 0.7892 y = 0.7816 y = 0.7891 y = 0.7817 y = 0.7890 y = 0.7818 y = 0.7889 y = 0.7819 y = 0.7888 y = 0.7820 y = 0.7887 y = 0.7821 y = 0.7886 y = 0.7822 y = 0.7886 y = 0.7823 ap = 0.7605 0.7729 0.7771 0.7791 0.7804 0.7812 0.7818 0.7823 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 y = 0.7915 y = 0.7794 y = 0.7912 y = 0.7797 y = 0.7910 y = 0.7800 y = 0.7907 y = 0.7802 y = 0.7905 y = 0.7804 y = 0.7903 y = 0.7806 y = 0.7901 y = 0.7808 y = 0.7899 y = 0.7809 y = 0.7898 y = 0.7811 y = 0.7896 y = 0.7812 y = 0.7895 y = 0.7814 y = 0.7894 y = 0.7815 y = 0.7892 y = 0.7816 y = 0.7891 y = 0.7817 y = 0.7890 y = 0.7818 y = 0.7889 y = 0.7819 y = 0.7888 y = 0.7820 y = 0.7887 y = 0.7821 y = 0.7886 y = 0.7822 y = 0.7886 y = 0.7823 y = 0.7885 y = 0.7823 y = 0.7884 y = 0.7824 y = 0.7883 y = 0.7825 y = 0.7883 y = 0.7826 y = 0.7882 y = 0.7826 ap = 0.7605 0.7729 0.7771 0.7791 0.7804 0.7812 0.7818 0.7823 0.7826 y = 0 y = 1 y = 0.6667 y = 0.8667 y = 0.7238 y = 0.8349 y = 0.7440 y = 0.8209 y = 0.7543 y = 0.8131 y = 0.7605 y = 0.8081 y = 0.7646 y = 0.8046 y = 0.7676 y = 0.8020 y = 0.7698 y = 0.8001 y = 0.7715 y = 0.7985 y = 0.7729 y = 0.7973 y = 0.7740 y = 0.7963 y = 0.7750 y = 0.7954 y = 0.7758 y = 0.7947 y = 0.7765 y = 0.7940 y = 0.7771 y = 0.7935 y = 0.7776 y = 0.7930 y = 0.7780 y = 0.7925 y = 0.7785 y = 0.7922 y = 0.7788 y = 0.7918 y = 0.7791 y = 0.7915 y = 0.7794 y = 0.7912 y = 0.7797 y = 0.7910 y = 0.7800 y = 0.7907 y = 0.7802 y = 0.7905 y = 0.7804 y = 0.7903 y = 0.7806 y = 0.7901 y = 0.7808 y = 0.7899 y = 0.7809 y = 0.7898 y = 0.7811 y = 0.7896 y = 0.7812 y = 0.7895 y = 0.7814 y = 0.7894 y = 0.7815 y = 0.7892 y = 0.7816 y = 0.7891 y = 0.7817 y = 0.7890 y = 0....