Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static void findConstants(double[] n_p, double[] n_m, double[] d_p, double[] d_m, double[] bd_p, double[] bd_m, double std_dev) { double div = Math.sqrt(2 * 3.141593) * std_dev; double x0 = -1.783 / std_dev; double x1 = -1.723 / std_dev; double x2 = 0.6318 / std_dev; double x3 = 1.997 / std_dev; double x4 = 1.6803 / div; double x5 = 3.735 / div; double x6 = -0.6803 / div; double x7 = -0.2598 / div; int i; n_p[0] = x4 + x6; n_p[1] = (Math.exp(x1) * (x7 * Math.sin(x3) - (x6 + 2 * x4) * Math.cos(x3)) + Math.exp(x0) * (x5 * Math.sin(x2) - (2 * x6 + x4) * Math.cos(x2))); n_p[2] = (2 * Math.exp(x0 + x1) * ((x4 + x6) * Math.cos(x3) * Math.cos(x2) - x5 * Math.cos(x3) * Math.sin(x2) - x7 * Math.cos(x2) * Math.sin(x3)) + x6 * Math.exp(2 * x0) + x4 * Math.exp(2 * x1)); n_p[3] = (Math.exp(x1 + 2 * x0) * (x7 * Math.sin(x3) - x6 * Math.cos(x3)) + Math.exp(x0 + 2 * x1) * (x5 * Math.sin(x2) - x4 * Math.cos(x2))); n_p[4] = 0.0; d_p[0] = 0.0; d_p[1] = -2 * Math.exp(x1) * Math.cos(x3) - 2 * Math.exp(x0) * Math.cos(x2); d_p[2] = 4 * Math.cos(x3) * Math.cos(x2) * Math.exp(x0 + x1) + Math.exp(2 * x1) + Math.exp(2 * x0); d_p[3] = -2 * Math.cos(x2) * Math.exp(x0 + 2 * x1) - 2 * Math.cos(x3) * Math.exp(x1 + 2 * x0); d_p[4] = Math.exp(2 * x0 + 2 * x1); for (i = 0; i <= 4; i++) { d_m[i] = d_p[i]; } n_m[0] = 0.0; for (i = 1; i <= 4; i++) { n_m[i] = n_p[i] - d_p[i] * n_p[0]; } double sum_n_p, sum_n_m, sum_d; double a, b; sum_n_p = 0.0; sum_n_m = 0.0; sum_d = 0.0; for (i = 0; i <= 4; i++) { sum_n_p += n_p[i]; sum_n_m += n_m[i]; sum_d += d_p[i]; } a = sum_n_p / (1.0 + sum_d); b = sum_n_m / (1.0 + sum_d); for (i = 0; i <= 4; i++) { bd_p[i] = d_p[i] * a; bd_m[i] = d_m[i] * b; } } }