本文整理匯總了Java中java.lang.Math.pow方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.pow方法的具體用法?Java Math.pow怎麽用?Java Math.pow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Math
的用法示例。
在下文中一共展示了Math.pow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: k
import java.lang.Math; //導入方法依賴的package包/類
@Override
public double k(double[] x, double[] y) {
if (x.length != y.length)
throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
//Inner product
double xx = 0;
double yy = 0;
double xy = 0;
for (int i = 0; i < x.length; i++){
xx += x[i] * x[i];
yy += y[i] * y[i];
xy += x[i] * y[i];
}
double m = constant * Math.sqrt(-2.0 * xy + xx + yy);
return 1.0 / Math.pow(1.0 + m * m, omega);
}
示例2: k
import java.lang.Math; //導入方法依賴的package包/類
@Override
public double k(int[] x, int[] y) {
double dot = 0.0;
for (int p1 = 0, p2 = 0; p1 < x.length && p2 < y.length; ) {
int i1 = x[p1];
int i2 = y[p2];
if (i1 == i2) {
dot++;
p1++;
p2++;
} else if (i1 > i2) {
p2++;
} else {
p1++;
}
}
return Math.pow(scale * dot + offset, degree);
}
示例3: RandomCircleSet
import java.lang.Math; //導入方法依賴的package包/類
public RandomCircleSet(int kappa, int numAlter, int numFeature, int size) {
this.kappa = kappa;
this.numAlter = numAlter;
this.numFeature = numFeature;
mu = (int)Math.ceil((double)numFeature/(double)kappa);
this.size = size;
counter = 0;
long a, f;
a = (long)Math.pow(2, numAlter);
f = (long)Math.pow(2, numFeature);
long s = 1;
for(long i=1; i<=kappa; i++) {
s *= (a-i);
s *= (f-i);
s /= i;
}
System.out.println("The RandomCircleSet iterator generate " + size + " out of " + s + " possibilities.");
}
示例4: clickedOn
import java.lang.Math; //導入方法依賴的package包/類
/**
* checks if pt is on root and calls itself recursivly to check root's children
* @param pt the point we want to check the location of
* @param root the message we want to check if the point is on
* @return root if pt is on it, null otherwise
* @author Paul Best
*/
public Message clickedOn(Point pt, Message root){
Message answer;
for(int i = 0; i<root.getChildren().size();i++){
answer = clickedOn(pt,root.getChildren().get(i));
if(answer!=null){
return answer;
}
}
if(Math.pow(Math.pow(pt.x/mScaleFactor-(root.getGoval().getX()+mPosX/mScaleFactor),2)+Math.pow(pt.y/mScaleFactor-(root.getGoval().getY()+mPosY/mScaleFactor),2),0.5)<root.getGoval().getRay()){
return root;
}
else{
return null;
}
}
示例5: getBoard
import java.lang.Math; //導入方法依賴的package包/類
public String getBoard(){
String result="";
int counter=2;
int sum=0;
ArrayList<Integer> triplets = new ArrayList<Integer>();
for(int x=0; x<WIDTH; x++){
for(int y=HEIGHT-1;y>=0;y--){
Tile t=allTiles[x][y];
sum+=(Math.pow(4,counter)*t.getState());
if(counter==0){
triplets.add(sum);
sum=0;
counter=3;
}
counter--;
}
}
if(counter!=2){
triplets.add(sum);
}
for(int i:triplets){
result+=charTable.toCharArray()[i];
}
return result;
}
示例6: stirf
import java.lang.Math; //導入方法依賴的package包/類
/**
* Stirf double.
*
* @param x the x
* @return the double
* @throws ArithmeticException the arithmetic exception
*/
/* Gamma function computed by Stirling's formula.
* The polynomial STIR is valid for 33 <= x <= 172.
Cephes Math Library Release 2.2: July, 1992
Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
*/
static private double stirf(double x) throws ArithmeticException {
double STIR[] = {
7.87311395793093628397E-4,
-2.29549961613378126380E-4,
-2.68132617805781232825E-3,
3.47222221605458667310E-3,
8.33333333333482257126E-2,
};
double MAXSTIR = 143.01608;
double w = 1.0/x;
double y = Math.exp(x);
w = 1.0 + w * polevl( w, STIR, 4 );
if( x > MAXSTIR ) {
/* Avoid overflow in Math.pow() */
double v = Math.pow( x, 0.5 * x - 0.25 );
y = v * (v / y);
} else {
y = Math.pow( x, x - 0.5 ) / y;
}
y = SQTPI * y * w;
return y;
}
示例7: pseries
import java.lang.Math; //導入方法依賴的package包/類
/**
* Pseries double.
*
* @param a the a
* @param b the b
* @param x the x
* @return the double
* @throws ArithmeticException the arithmetic exception
*/
static private double pseries( double a, double b, double x )
throws ArithmeticException {
double s, t, u, v, n, t1, z, ai;
ai = 1.0 / a;
u = (1.0 - b) * x;
v = u / (a + 1.0);
t1 = v;
t = u;
n = 2.0;
s = 0.0;
z = MACHEP * ai;
while( Math.abs(v) > z ) {
u = (n - b) * x / n;
t *= u;
v = t / (a + n);
s += v;
n += 1.0;
}
s += t1;
s += ai;
u = a * Math.log(x);
if( (a+b) < MAXGAM && Math.abs(u) < MAXLOG ) {
t = gamma(a+b)/(gamma(a)*gamma(b));
s = s * t * Math.pow(x,a);
} else {
t = lgamma(a+b) - lgamma(a) - lgamma(b) + u + Math.log(s);
if( t < MINLOG ) s = 0.0;
else s = Math.exp(t);
}
return s;
}
示例8: computeSpearmanCorrelation
import java.lang.Math; //導入方法依賴的package包/類
public static double computeSpearmanCorrelation(double[] rank_0, double[] rank_1)
{
double rho = -1;
double num = 0;
double den = 0;
for(int i = 0; i < rank_0.length; i++)
num += Math.pow((rank_0[i] - rank_1[i]),2);
den = rank_0.length * (Math.pow(rank_0.length, 2) - 1);
if(den == 0)
return rho;
rho = 1 - 6*num/den;
return rho;
}
示例9: series_2
import java.lang.Math; //導入方法依賴的package包/類
void series_2(int n){
double sum = 1;
for(int i=1; i<n; i++)
{
if(n > 1){
sum += 1/Math.pow(2,i);
}else{
sum = 1;
break;
}
}
System.out.println("Sum for "+n+" terms: "+sum);
}
示例10: getChunk
import java.lang.Math; //導入方法依賴的package包/類
public static long getChunk(int chunk, int num) {
// Get rid of numbers before
num %= Math.pow(10, chunk * 5);
// Get rid of numbers after chunk
num /= Math.pow(10, (chunk - 1) * 5);
return num;
}
示例11: calculateVariance
import java.lang.Math; //導入方法依賴的package包/類
public static double calculateVariance(int [] population, int n){
double mean = calculateMean(population,n);
double sum = 0;
for(int i : population){
double temp = (double) i - mean;
sum += Math.pow(temp,2);
}
return sum/n;
}
示例12: norm
import java.lang.Math; //導入方法依賴的package包/類
public double norm(double[] v, int p) {
int nLen = v.length; // get the length of the vector
double sum = 0; // the sum of the powers
for (int i = 0; i < nLen; i++) { // sum up the powers
sum += Math.pow(v[i], (double)p);
}
return Math.pow(sum, (double)1/p);
}
示例13: main
import java.lang.Math; //導入方法依賴的package包/類
public static void main(String[] args) {
double number = 4.321;
number = Math.pow(number, 4.0);
System.out.println(number);
}
示例14: CircleSet
import java.lang.Math; //導入方法依賴的package包/類
public CircleSet(int kappa, int numAlter, int numFeature) {
this.kappa = kappa;
this.numAlter = numAlter;
this.numFeature = numFeature;
int a, f;
a = (int)Math.pow(2, numAlter);
f = (int)Math.pow(2, numFeature);
int s = 1;
for(int i=1; i<=kappa; i++) {
s *= (a-i);
s *= (f-i);
s /= i;
}
size = s;
System.out.println("!!!!!!!! THERE ARE " + size + " POSSIBILITIES !!!!!!!!");
circleSet = new Circle[kappa];
for(int i=0; i<kappa; i++)
circleSet[i] = new Circle(numAlter, numFeature);
featPermunationiter = new BCPPermutation(kappa, numFeature);
for(int i=0; i<kappa; i++) {
for(int j=0; j<numFeature; j++) {
circleSet[i].removeFeature(j);
}
}
alterCombinationiter = new BCPCombination(kappa, numAlter);
System.out.println("alterCombinationiter.size():" + alterCombinationiter.size());
int[][] firstAlterCombination = alterCombinationiter.iterator().next();
for(int i=0; i<kappa; i++) {
for(int j=0; j<numAlter; j++) {
System.out.println("i:" + i + " j:" + j);
if(firstAlterCombination[i][j] == 1)
circleSet[i].addAlter(j);
else
circleSet[i].removeAlter(j);
}
}
}
示例15: size
import java.lang.Math; //導入方法依賴的package包/類
@Override
public int size() {
return (int)Math.pow(2, numElement)-1;
}