Cody

Solution 573329

Submitted on 3 Feb 2015 by James
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

a = 1 3 5 7 9 ma4 = 1 3 1 3 1 ma4 = 1 -1 1 -1 1 p4 = -0.8584 0.4749 -0.3251 0.2464 -0.1981 ans = -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

a = 1 3 5 7 9 11 13 15 17 19 ma4 = 1 3 1 3 1 3 1 3 1 3 ma4 = 1 -1 1 -1 1 -1 1 -1 1 -1 p4 = Columns 1 through 9 -0.8584 0.4749 -0.3251 0.2464 -0.1981 0.1655 -0.1421 0.1245 -0.1108 Column 10 0.0998 ans = 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

a = Columns 1 through 16 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 Columns 17 through 25 33 35 37 39 41 43 45 47 49 ma4 = Columns 1 through 16 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 17 through 25 1 3 1 3 1 3 1 3 1 ma4 = Columns 1 through 16 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 17 through 25 1 -1 1 -1 1 -1 1 -1 1 p4 = Columns 1 through 9 -0.8584 0.4749 -0.3251 0.2464 -0.1981 0.1655 -0.1421 0.1245 -0.1108 Columns 10 through 18 0.0998 -0.0907 0.0832 -0.0768 0.0713 -0.0666 0.0624 -0.0588 0.0555 Columns 19 through 25 -0.0526 0.0500 -0.0476 0.0454 -0.0435 0.0416 -0.0400 ans = -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

a = Columns 1 through 16 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 Columns 17 through 32 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 Columns 33 through 48 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 Columns 49 through 64 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 Columns 65 through 80 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 Columns 81 through 96 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 Columns 97 through 100 193 195 197 199 ma4 = Columns 1 through 16 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 17 through 32 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 33 through 48 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 49 through 64 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 65 through 80 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 81 through 96 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 Columns 97 through 100 1 3 1 3 ma4 = Columns 1 through 16 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 17 through 32 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 33 through 48 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 49 through 64 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 65 through 80 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 81 through 96 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 Columns 97 through 100 1 -1 1 -1 p4 = Columns 1 through 9 -0.8584 0.4749 -0.3251 0.2464 -0.1981 0.1655 -0.1421 0.1245 -0.1108 Columns 10 through 18 0.0998 -0.0907 0.0832 -0.0768 0.0713 -0.0666 0.0624 -0.0588 0.0555 Columns 19 through 27 -0.0526 0.0500 -0.0476 0.0454 -0.0435 0.0416 -0.0400 0.0384 -0.0370 Columns 28 through 36 0.0357 -0.0345 0.0333 -0.0322 0.0312 -0.0303 0.0294 -0.0286 0.0278 Columns 37 through 45 -0.0270 0.0263 -0.0256 0.0250 -0.0244 0.0238 -0.0233 0.0227 -0.0222 Columns 46 through 54 0.0217 -0.0213 0.0208 -0.0204 0.0200 -0.0196 0.0192 -0.0189 0.0185 Columns 55 through 63 -0.0182 0.0179 -0.0175 0.0172 -0.0169 0.0167 -0.0164 0.0161 -0.0159 Columns 64 through 72 0.0156 -0.0154 0.0152 -0.0149 0.0147 -0.0145 0.0143 -0.0141 0.0139 Columns 73 through 81 -0.0137 0.0135 -0.0133 0.0132 -0.0130 0.0128 -0.0127 0.0125 -0.0123 Columns 82 through 90 0.0122 -0.0120 0.0119 -0.0118 0.0116 -0.0115 0.0114 -0.0112 0.0111 Columns 91 through 99 -0.0110 0.0109 -0.0108 0.0106 -0.0105 0.0104 -0.0103 0.0102 -0.0101 Column 100 0.0100 ans = Columns 1 through 9 0.0998 0.0500 0.0333 0.0250 0.0200 0.0167 0.0143 0.0125 0.0111 Column 10 0.0100

Suggested Problems