Java Array Normalize normalize(double[] a)

Here you can find the source of normalize(double[] a)

Description

normalize

License

Open Source License

Declaration

public static double[] normalize(double[] a) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double[] normalize(double[] a) {
        double l = length(a);
        if (l < 0.1) {
            l = 0.1;//from   w  ww  . ja va 2  s. c  om
        }
        double[] v = new double[a.length];

        for (int i = 0; i < a.length; ++i) {
            v[i] = a[i] / l;
        }

        return v;
    }

    public static double length(double[] v) {
        return Math.sqrt(lengthSquare(v));
    }

    public static double lengthSquare(double[] v) {
        double s = 0;
        for (double x : v) {
            s += x * x;
        }
        return s;
    }
}

Related

  1. normalize(double arr[])
  2. normalize(double wheelSpeeds[])
  3. normalize(double[] a)
  4. normalize(double[] a)
  5. normalize(double[] a)
  6. normalize(double[] a)
  7. normalize(double[] ar)
  8. normalize(double[] array)
  9. normalize(double[] array)