Cody

Solution 1413739

Submitted on 11 Jan 2018 by baruch braude
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
filetext = fileread('myCos.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
filetext = fileread('myCos.m'); trigUsed = any(strfind(filetext, 'cos')) || any(strfind(filetext, 'sin')) ||... any(strfind(filetext, 'exp')); assert(~trigUsed, 'Cannot use MATLAB trigonometric functions')

3   Pass
x = 0; assert(abs(myCos(x)-cos(x)) < 0.0001)

y = [] n = 0 [Warning: Too many FOR loop iterations. Stopping after 9223372036854775806 iterations.] s = 1 n = 1 y = 1 s = 0

4   Pass
x = pi; assert(abs(myCos(x)-cos(x)) < 0.0001)

y = [] n = 0 [Warning: Too many FOR loop iterations. Stopping after 9223372036854775806 iterations.] s = 1 n = 1 y = 1 s = -4.9348 n = 2 y = -3.9348 s = 4.0587 n = 3 y = 0.1239 s = -1.3353 n = 4 y = -1.2114 s = 0.2353 n = 5 y = -0.9760 s = -0.0258 n = 6 y = -1.0018 s = 0.0019 n = 7 y = -0.9999 s = -1.0464e-04 n = 8 y = -1.0000 s = 4.3031e-06

5   Pass
x = pi/2; assert(abs(myCos(x)-cos(x)) < 0.0001)

y = [] n = 0 [Warning: Too many FOR loop iterations. Stopping after 9223372036854775806 iterations.] s = 1 n = 1 y = 1 s = -1.2337 n = 2 y = -0.2337 s = 0.2537 n = 3 y = 0.0200 s = -0.0209 n = 4 y = -8.9452e-04 s = 9.1926e-04 n = 5 y = 2.4737e-05 s = -2.5202e-05

6   Pass
x = 5*pi/3; assert(abs(myCos(x)-cos(x)) < 0.0001)

y = [] n = 0 [Warning: Too many FOR loop iterations. Stopping after 9223372036854775806 iterations.] s = 1 n = 1 y = 1 s = -13.7078 n = 2 y = -12.7078 s = 31.3172 n = 3 y = 18.6094 s = -28.6193 n = 4 y = -10.0099 s = 14.0110 n = 5 y = 4.0011 s = -4.2680 n = 6 y = -0.2669 s = 0.8864 n = 7 y = 0.6195 s = -0.1335 n = 8 y = 0.4860 s = 0.0153 n = 9 y = 0.5013 s = -0.0014 n = 10 y = 0.4999 s = 9.8593e-05

Suggested Problems

More from this Author25