Java Vector Length Get vectorLength(double[] vector)

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

Description

Returns the vector length (sqrt(sum(x_i))

License

Apache License

Parameter

Parameter Description
vector the vector to return the vector length for

Return

the vector length of the passed in array

Declaration

public static double vectorLength(double[] vector) 

Method Source Code

//package com.java2s;
/*/*from w w w  .  j a v  a2  s  .com*/
 *  * Copyright 2016 Skymind, Inc.
 *  *
 *  *    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 vector length (sqrt(sum(x_i))
     *
     * @param vector the vector to return the vector length for
     * @return the vector length of the passed in array
     */
    public static double vectorLength(double[] vector) {
        double ret = 0;
        if (vector == null)
            return ret;
        else {
            for (double aVector : vector) {
                ret += Math.pow(aVector, 2);
            }

        }
        return ret;
    }
}

Related

  1. vectorLength(Double[] vector)
  2. vectorLength(double[] vector)
  3. vectorLengthDyDx(double dy, double dx)
  4. vectorLengthSquared(float vx, float vy, float vz)