title: The levenberg-marquardt method for solving non-linear equations
body: <p>I tried implement the levenberg-marquardt method for solving non-linear equations on Julia based on <a href="http://mads.lanl.gov/presentations/Leif_LM_presentation_m.pdf" rel="nofollow">Numerical Optimization using the 
  Levenberg-Marquardt Algorithm</a> presentation. This my code:</p>
  
  <pre><code>function get_J(ArrOfFunc,X,delta)
    N = length(ArrOfFunc)
    J = zeros(Float64,N,N)
    for i = 1:N
      for j=1:N
        Temp = copy(X);
        Temp[j]=Temp[j]+delta;
        J[i,j] = (ArrOfFunc[i](Temp)-ArrOfFunc[i](X))/delta;
      end
    end
    return J
  end
  
  function get_resudial(ArrOfFunc,Arg)
    return  map((x)-&gt;x(Arg),ArrOfFunc)
  end
  
  function lm_solve(Funcs,Init)
    X = copy(Init)
    delta = 0.01;
    Lambda = 0.01;
    Factor = 2;
    J = get_J(Funcs,X,delta)
    R = get_resudial(Funcs,X)
    N = 5
    for t = 1:N
  
      G = J'*J+Lambda.*eye(length(X))
      dC = J'*R
      C = sum(R.*R)/2;
      Xnew = X-(inv(G)\dC);
      Rnew = get_resudial(Funcs,Xnew)
      Cnew =  sum(Rnew.*Rnew)/2;
      if ( Cnew &lt; C)
        X = Xnew;
        R = Rnew;
        Lambda = Lambda/Factor;
        J = get_J(Funcs,X,delta)
      else
        Lambda = Lambda*Factor;
      end
      if(maximum(abs(Rnew)) &lt; 0.001)
        return X
      end
    end
    return X
  end
  
  function test()
    ArrOfFunc = [
    (X)-&gt;X[1]+X[2]-2;
    (X)-&gt;X[1]-X[2]
    ];
  
    X = lm_solve(ArrOfFunc,Float64[3;3])
    println(X)
    return X
  end
  </code></pre>
  
  <p>But from any starting point the step not accepted. What's I doing wrong?
  Any help would be appreciated.</p>