mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-20 06:34:26 +01:00
17 lines
427 B
Matlab
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
|