Cody

Problem 42588. Derivative function

Solution 1726488

Submitted on 13 Feb 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
f = @sin; df = Derivative(f); x = 10*rand(10000,1); dy = cos(x); assert(max(abs((dy-df(x))./dy))<1e-13)

Undefined function 'syms' for input arguments of type 'char'. Error in Derivative (line 2) syms y Error in Test1 (line 2) df = Derivative(f);

2   Fail
f = @log; df = Derivative(f); x = exp(500*rand(10000,1)); dy = 1./x; assert(max(abs((dy-df(x))./dy))<1e-13)

Undefined function 'syms' for input arguments of type 'char'. Error in Derivative (line 2) syms y Error in Test2 (line 2) df = Derivative(f);

3   Fail
f = @exp; df = Derivative(f); x = 50*(rand(10000,1)-0.5); dy = exp(x); assert(max(abs((dy-df(x))./dy))<1e-13)

Undefined function 'syms' for input arguments of type 'char'. Error in Derivative (line 2) syms y Error in Test3 (line 2) df = Derivative(f);

4   Fail
t = 10*rand; f = @(x)1./(x+t); df = Derivative(f); x = 100*(rand(10000,1)-0.5); x(x==-t) = 1; dy = -1./(x+t).^2; assert(max(abs((dy-df(x))./dy))<1e-13)

Undefined function 'syms' for input arguments of type 'char'. Error in Derivative (line 2) syms y Error in Test4 (line 3) df = Derivative(f);

5   Fail
t = 10*rand-5; f = @(x)atan(t*x); df = Derivative(f); x = 100*(rand(10000,1)-0.5); dy = t./(t^2*x.^2 + 1); assert(max(abs((dy-df(x))./dy))<1e-13)

Undefined function 'syms' for input arguments of type 'char'. Error in Derivative (line 2) syms y Error in Test5 (line 3) df = Derivative(f);

6   Fail
for t = 2:6 f = @(x)t.^x./(sin(x).^t+cos(x).^t); df = Derivative(f); x = 3+rand(10000,1); dy = (t.^x.*log(t))./(cos(x).^t+sin(x).^t)-... (t.^x.*(t.*cos(x).*sin(x).^(t-1)-... t.*cos(x).^(t-1).*sin(x)))./(cos(x).^t+sin(x).^t).^2; assert(max(abs((dy-df(x))./dy))<1e-13) end

Undefined function 'syms' for input arguments of type 'char'. Error in Derivative (line 2) syms y Error in Test6 (line 3) df = Derivative(f);