### Question:
Multilateration { public LeastSquaresOptimizer.Optimum findOptimum() { double[][] positions = getPositions(beacons); double[] distances = getDistances(beacons); return findOptimum(positions, distances); } Multilateration(List<Beacon> beacons); static double[][] getPositions(List<Beacon> beacons); static double[] getDistances(List<Beacon> beacons); LeastSquaresOptimizer.Optimum findOptimum(); static LeastSquaresOptimizer.Optimum findOptimum(double[][] positions, double[] distances); static Location getLocation(LeastSquaresOptimizer.Optimum optimum); double getRMS(); List<Beacon> getBeacons(); Location getLocation(); float getDeviation(); LeastSquaresOptimizer.Optimum getOptimum(); static final int ROOT_MEAN_SQUARE_NOT_SET; }### Answer:
@Test public void findOptimum_perfectDistances_perfectOptimum() throws Exception { double[] expectedCenter = new double[]{0, 0}; double[][] positions = new double[][]{{-10, 10}, {10, 10}, {10, -10}, {-10, -10}}; double distance = 7.07106781; double[] distances = new double[]{distance, distance, distance, distance}; LeastSquaresOptimizer.Optimum optimum = Multilateration.findOptimum(positions, distances); double[] actualCenter = optimum.getPoint().toArray(); assertEquals(expectedCenter[0], actualCenter[0], 0); assertEquals(expectedCenter[1], actualCenter[1], 0); }
@Test public void findOptimum_realisticDistances_realisticOptimum() throws Exception { double[] expectedCenter = new double[]{0, 0}; double[][] positions = new double[][]{{-10, 10}, {10, 10}, {10, -10}, {-10, -10}}; double[] distances = new double[]{7.02, 7.05, 7.09, 7.1}; LeastSquaresOptimizer.Optimum optimum = Multilateration.findOptimum(positions, distances); double[] actualCenter = optimum.getPoint().toArray(); assertEquals(expectedCenter[0], actualCenter[0], 0.2); assertEquals(expectedCenter[1], actualCenter[1], 0.2); }