Java Vector Normalize vectorNorm(final double[] vector)

Here you can find the source of vectorNorm(final double[] vector)

Description

Returns the norm of a vector.

License

Apache License

Parameter

Parameter Description
vector a parameter

Declaration

public static double vectorNorm(final double[] vector) 

Method Source Code

//package com.java2s;
/*/*w  w w. j  a  v a2 s .c  o  m*/
 * Copyright 2016 Langhammer, Tim | Earth >> Europe >> Potsdam |
 * {@literal @}<a href="mailto:tlhammer@mailbox.org" alt="email">mail</a> |
 * "Tolerance first".
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns the norm of a vector.
     * <p/>
     * @param vector
     * @return
     */
    public static double vectorNorm(final double[] vector) {
        if (vector == null) {
            throw new NullPointerException("Null vector@vectorNorm!");
        }

        double temp = 0;
        for (int i = 0; i < vector.length; i++) {
            temp += vector[i] * vector[i];
        }

        return Math.sqrt(temp);
    }
}

Related

  1. vectorNorm(double[] v)
  2. vectorNorm(double[] vector)
  3. vectorNorm(float[] v)
  4. vectorNormalize(double[] v)
  5. vectorNorms(boolean[] in, int veclen)