clc
clear

function y = derivar(f, v, n, h)
    if n == 0 then
        y = f(v)
    else
        y = (derivar(f, v + h, n - 1, h) - derivar(f, v, n - 1, h)) / h
    end
endfunction

function y = f(x)
    y = (x - 1) .^ 7
endfunction

function y = g(x)
    y = sin(x) + exp(x)
endfunction

x = 4.5;
paso = 1e-5;
orden = 2

mprintf("\n");

mprintf("Intento  f: %f\n", derivar(f, x, orden, paso));
mprintf("Oficial  f: %f\n", numderivative(f, x, order=2));
mprintf("Verdadero f: %f\n", 7 * 6 * (x - 1)^5);

mprintf("Intento  g: %f\n", derivar(g, x, orden, paso));
mprintf("Oficial  g: %f\n", numderivative(g, x, order=2));
mprintf("Verdadero g: %f\n", -sin(x) + exp(x));
