import java.util.Date;
import java.text.DecimalFormat;

import ORG.netlib.math.complexKorl.Complex;


/**
 *  Class for solve system of linear equation
 */
public class Scp3Int{

    public static final int dim = 5;
    public static int iters = 1000;
    public static double[] b = new double[dim];


    /**
      */
    public static void main (String[] args) {

        for (int it =  1; it <= 5; it++) {
            long start = System.currentTimeMillis();


            for (int i =  0; i < iters; i++) {
                for (int ib = 0; ib < dim; ib++) {
                    b[ib] = 1.0;
                }
            
                test();
            }

            for (int i =  0; i < dim; i++) {
                System.out.println(b[i]);
            }

            long end = System.currentTimeMillis();
            System.out.println("Total time = "+ (end-start)*0.001);
        }
    }


    public static double addKorl(double a1, double a2) {
        Complex z1 = new Complex(a1, 0.0);
        Complex z2 = new Complex(a2, 0.0);
        Complex z = z1.add(z2);
        return z.re();
    }
  

    public static double subKorl(double a1, double a2) {
        Complex z1 = new Complex(a1, 0.0);
        Complex z2 = new Complex(a2, 0.0);
        Complex z = z1.sub(z2);
        return z.re();
    }


    public static double mulKorl(double a1, double a2) {
        Complex z1 = new Complex(a1, 0.0);
        Complex z2 = new Complex(a2, 0.0);
        Complex z = z1.mul(z2);
        return z.re();
    }


    public static double divKorl(double a1, double a2) {
        Complex z1 = new Complex(a1, 0.0);
        Complex z2 = new Complex(a2, 0.0);
        Complex z = z1.div(z2);
        return z.re();
    }
    

    public static void test() {
        double [][] A = new double[dim][dim];
        double [] bb  = new double[dim];

        for (int ib = 0; ib < dim; ib++) {
            bb[ib] = b[ib];
        }

        for (int i = 0; i < dim; i++) {
            for (int j = 0; j < dim; j++) {
            A[i][j] = 0.0;
            }
        }

        for (int i = 1; i < dim; i++) {
            A[i][i-1] = 1.0;
        }

        for (int i = 0; i < dim; i++) {
            A[0][i] = 1.0;
        }

        for (int i = 0; i < dim; i++) {
            for (int j = 0; j < dim; j++) {
                if (j != i) {
                    double rrr = divKorl(A[j][i], A[i][i]);
                    for (int k = 0; k < dim; k++) {
                        A[j][k] = subKorl(A[j][k], mulKorl(A[i][k],rrr));

                    }
                    bb[j] = subKorl(bb[j], mulKorl(rrr, bb[i]));
                };
            }
        }

        for (int i = 0; i < dim; i++) {
            bb[i] = divKorl(bb[i], A[i][i]);
        }
        
        for (int ib = 0; ib < dim; ib++) {
            b[ib] = bb[ib];
        }

    }

}