Solution 7-1
Here is a suggested solution for Étude 7-1.
calculus.erl
%% @author J D Eisenberg <jdavid.eisenberg@gmail.com>
%% @doc Find the derivative of a function Fn at point X.
%% @copyright 2013 J D Eisenberg
%% @version 0.1
-
module
(
calculus
).
-
export
([
derivative
/
2
]).
%% @doc Calculate derivative by classical definition.
%% (Fn(X + H) - Fn(X)) / H
-
spec
(
derivative
(
function
(),
float
())
->
float
()).
derivative
(
Fn
,
X
)
->
Delta
=
1
.
0
e
-
10
,
(
Fn
(
X
+
Delta
)
-
Fn
(
X
))
/
Delta
.
Get Études for Erlang now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.