Cody

# Problem 46918. Numerical differentiation with high precision

Solution 3411063

Submitted on 26 Oct 2020 by William
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
fun = @sin; for k = 1:5 x = randn; assert(abs(numerical_diff(fun,x) - cos(x)) < 1e-12) end

2   Pass
fun = @(x)x^(9/2); for k = 1:5 x = abs(randn); assert(abs(numerical_diff(fun,x) - (9/2)*x^(7/2)) < 1e-12); end

3   Pass
fun = @(x)exp(x)/(cos(x)^3+sin(x)^3); x = [ 0 pi/4 pi/2 pi ]; Df = [ 1 exp(pi/4)*sqrt(2) exp(pi/2) -exp(pi)]; for k = 1:4 assert(abs(numerical_diff(fun,x(k)) - Df(k)) < 1e-12); end

4   Pass
fun = @(x)exp(x)/sqrt(cos(x)^3+sin(x)^3); x = [ -pi/8 0 pi/8 pi/4 pi/2 ]; Df = [ 0.042678767134941 1 2.15903261751524 exp(pi/4)*2^(1/4) exp(pi/2) -exp(pi)]; for k = 1:5 assert(abs(numerical_diff(fun,x(k)) - Df(k)) < 1e-12) end

5   Pass
str = fileread('numerical_diff.m'); % sorry, no regexp hacks :-) assert(isempty(regexp(str,'regexp')));

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!