WUT_Computer_Science/ENUME/references/szopinski-enume/projB/deriv.m
2021-11-10 13:12:25 +01:00

17 lines
427 B
Matlab

% ENUME MICHAŁ SZOPIŃSKI
% PROJECT B NUMBER 60
% https://github.com/Lachcim/szopinski-enume
% calculate the nth derivative of func at x
function y = deriv(func, x, deg)
% base case: zeroth derivative
if deg == 0
y = func(x);
return
end
% recurse to find the nth derivative
step = sqrt(eps);
y = (deriv(func, x + step, deg - 1) - deriv(func, x - step, deg - 1)) / (2 * step);
end