Java Array Min Value min(double[] matrix)

Here you can find the source of min(double[] matrix)

Description

Compute the minimum value of a 1d array.

License

Open Source License

Parameter

Parameter Description
matrix array

Return

min

Declaration

public static double min(double[] matrix) 

Method Source Code

//package com.java2s;
/*//from w w  w .  j a  va2s .co m
 * This file is part of TiPi (a Toolkit for Inverse Problems and Imaging)
 * developed by the MitiV project.
 *
 * Copyright (c) 2014 the MiTiV project, http://mitiv.univ-lyon1.fr/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

public class Main {
    /**
     * Compute the minimum value of a 1d array.
     *
     * @param matrix array
     * @return min
     */
    public static double min(double[] matrix) {
        double min = matrix[0];
        for (int i = 0; i < matrix.length; i++) {
            if (min > matrix[i]) {
                min = matrix[i];
            }
        }
        return min;
    }

    /**
     * Compute the minimum value of a 2d array.
     *
     * @param matrix array
     * @return min
     */
    public static double min(double[][] matrix) {
        double min = matrix[0][0];
        for (int col = 0; col < matrix.length; col++) {
            for (int row = 0; row < matrix[col].length; row++) {
                if (min > matrix[col][row]) {
                    min = matrix[col][row];
                }
            }
        }
        return min;
    }
}

Related

  1. min(double[] array)
  2. min(double[] array)
  3. min(double[] array)
  4. min(double[] da)
  5. min(double[] data)
  6. min(double[] numbers)
  7. min(double[] series)
  8. min(double[] vals)
  9. min(double[] values)