public static RealVector solve(RealMatrix A, RealVector y, int k) {
        RealVector xest = new ArrayRealVector(new double[A.getColumnDimension()]);
        RealMatrix z = A;
        RealVector v = y;

        int t = 0;
        int[] T2=null;


        while (t < 100) {
            //System.out.println(String.valueOf(t) +  " th iteration");

            double[] v_d = (A.transpose().operate(v)).toArray();

            for (int i = 0; i < v_d.length; i++)
                v_d[i] = Math.abs(v_d[i]);

            //CSUtils.showVector(new ArrayRealVector(v_d));
            ArrayIndexComparator comparator = new ArrayIndexComparator(v_d);
            Integer[] z1 = comparator.createIndexArray();
            Arrays.sort(z1, comparator);
            Arrays.sort(v_d);
            flipud(v_d, z1);

            Integer[] Omega = Arrays.copyOfRange(z1, 0, 2 * k);
            int[] T;

            if (t != 0) {
                T = unionSort(convertToIntArray(Omega), T2);
            } else {
                T = convertToIntArray(Omega);
                Arrays.sort(T);
            }

            //CSUtils.showIndexVector(T);

            RealMatrix At = MatrixUtils.createRealMatrix(A.getRowDimension(), T.length);

            //CSUtils.showMatrix(A);

            for(int i=0; i<T.length; i++){
//                System.out.println(String.valueOf(A.getColumnVector(T[i])));
                At.setColumnVector(i, A.getColumnVector(T[i]));
            }


            //Algorithm...
            RealMatrix At_I = new SingularValueDecomposition(At).getSolver().getInverse();
            RealVector b = At_I.operate(y);
            absRealVector(b);

            double[] k3 = b.toArray();
            ArrayIndexComparator comparator1 = new ArrayIndexComparator(k3);
            Integer[] z3 = comparator1.createIndexArray();
            Arrays.sort(z3,comparator1);
            Arrays.sort(k3);
            flipud(k3, z3);

            xest = new ArrayRealVector(A.getColumnDimension());
            Integer[] z3_1 = Arrays.copyOfRange(z3, 0, k);
            int count = 0;
            for(int i : z3_1){
                xest.setEntry(T[i],Math.abs(b.getEntry(i)));
                count++;
            }

            absRealVector(xest);

            double[] k2 = xest.toArray();
            ArrayIndexComparator comparator2 = new ArrayIndexComparator(k2);
            Integer[] z2 = comparator2.createIndexArray();
            Arrays.sort(z2,comparator2);
            Arrays.sort(k2);
            flipud(k2,z2);

            //xest = new ArrayealVector(xest_a);


            T2 = convertToIntArray(Arrays.copyOfRange(z2, 0, k));

            v = y.subtract(A.operate(xest));
            absRealVector(v);
            double n2 = v.getLInfNorm();

            if(n2<tol){
                break;
            }
            //System.out.println(xest);
            t++;
        }
        return xest;
    }