Java tutorial
//package com.java2s; //License from project: Open Source License import android.hardware.SensorManager; public class Main { public static double[] magnititute(double accx[], double accy[], double accz[]) { if (!((accx.length == accy.length) && (accy.length == accz.length))) { return null; } double result[] = new double[accx.length]; for (int i = 0; i < accx.length; i++) { result[i] = 0.0; double grav = SensorManager.GRAVITY_EARTH; result[i] += Math.pow(accx[i] / grav, 2.0); result[i] += Math.pow(accy[i] / grav, 2.0); result[i] += Math.pow(accz[i] / grav, 2.0); result[i] = Math.sqrt(result[i]); result[i] *= 310; } return result; } }