function Simula_Flujos_Potencia()
    % Parametros del Cicuito
    
    V  = 10; % Volts
    R  =  2; % ohms
    P  = 12; % Watts
    
    fprintf('La solución es %10.6f\n', NR(@fp, @der_fp, V/R, [V, R, P]));
end

function d = fp(I, p)
   V = p(1);
   R = p(2);
   PL = p(3);
   d = V*I - R*I*I - PL;
end

function der = der_fp(I, p)
   V = p(1);
   R = p(2);
   PL = p(3);
   der = V-2*R*I;
end

function r = NR(f, df, x1, p)
k=1;
while 1
    x2 = x1 - f(x1, p)/df(x1, p);
    if abs(f(x2, p)) < 1e-6 break;
    else x1 = x2;
    end;
    k = k+1;
end;
r = x2;
end

