package ejemplos;

/**
 * <p>Title: Metodo de Muller</p>
 * <p>Description: Resuelve un ecuación haciendo una aproximacion cuadratica</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: UMSNH</p>
 * @author Dr. Felix Calderon Solorio
 * @version 1.0
 */

public class ej058 {
  public static void main(String[] args) {

  }

  static public void Muller()
  {
    double x0 = 4.5, x1 = 5.5, x2 = 5.0, x3;
    double h0, h1, d0, d1, A, B, C;
    double den, raiz;

    do
    {

      h0 = x1 - x0;
      h1 = x2 - x1;
      d0 = (f(x1) - f(x0)) / h0;
      d1 = (f(x2) - f(x1)) / h1;

      A = (d1 - d0) / (h1 + h0);
      B = A * h1 + d1;
      C = f(x2);


      raiz = Math.sqrt(B * B - 4.0 * A * C);

      if (Math.abs(B + raiz) > Math.abs(B - raiz))
        den = B + raiz;
      else
        den = B - raiz;

      x3 = x2 - 2 * C / den;
      System.out.println(" x = " + x3 + " " + f(x3));

      x0 = x1;
      x1 = x2;
      x2 = x3;
    }while (Math.abs(f(x3)) > 0.000001);
  }
  static public double f(double x)
  {
    return(x*x*x - 13*x -12);
  }
}