// An example of searching for the root via the secant method

// for f_i[x_k] for i=1,2,...,n.

import java.lang.*;

public class Rootm {

public static void main(String argv[]) {

int n = 2;

intni = 10;

double del = 1e-6;

double x[] = {1.5, 1.5};

secantm(ni, x, del);

// Output the root obtained

System.out.println("The root is at x = " + x[0]

+ "; y = " + x[1]);

}

// Method to carry out the multivariable secant search.

public static void secantm(intni, double x[],

double del) {

int n = x.length;

double h = 2e-5;

int index[] = new int[n];

double a[][] = new double[n][n];

int k = 0;

double dx = 0.1;

while ((Math.abs(dx)>del) && (k<ni)) {

double b[] = f(x);

for (int i=0; i<n; ++i) {

for (int j=0; j<n; ++j) {

double hx = x[j]*h;

x[j] += hx;

double c[] = f(x);

a[i][j] = (c[i]-b[i])/hx;

}

}

dx = Math.sqrt(dx/n);

k++;

}

if (k==n) System.out.println("Convergence not" +

" found after " + ni + " iterations");

}

public static double[] solve(double a[][], double b[],

int index[]) {...}

public static void gaussian(double a[][], int index[])

{...}

// Method to provide function f_i[x_k].

public static double[] f(double x[]) {

double fx[] = new double[2];

fx[0] = Math.exp(x[0]*x[0])*Math.log(x[1])

-x[0]*x[0];

fx[1] = Math.exp(x[1])*Math.log(x[0])-x[1]*x[1];

return fx;

}

}