當前位置: 首頁>>代碼示例>>Java>>正文


Java Math.sqrt方法代碼示例

本文整理匯總了Java中java.lang.Math.sqrt方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.sqrt方法的具體用法?Java Math.sqrt怎麽用?Java Math.sqrt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.Math的用法示例。


在下文中一共展示了Math.sqrt方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.lang.Math; //導入方法依賴的package包/類
public static void main(String args[]) throws IOException{
    BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
    double a,b,c,d,x1,x2;
    System.out.print("Input value of a-->");
    a = Double.parseDouble(obj.readLine());
    System.out.print("Input value of b-->");
    b = Double.parseDouble(obj.readLine());
    System.out.print("Input value of c-->");
    c = Double.parseDouble(obj.readLine());
    d = (b*b) - (4*a*c);
    if( d < 0)
    {
        System.out.println("There are no real solution");
        System.exit(0);
    }

    x1 = (-b + Math.sqrt(d))/(2*a);
    x2 = (-b - Math.sqrt(d))/(2*a);
    System.out.println("Roots of equation are " + x1 + " and " + x2);
}
 
開發者ID:nvzard,項目名稱:Java-Lab-Programs,代碼行數:21,代碼來源:Quad.java

示例2: getStdDev

import java.lang.Math; //導入方法依賴的package包/類
private Number getStdDev() {

        if (!initialized) {
            return null;
        }

        return sample ? (n == 1) ? null    // NULL (not NaN) is correct in this case
                                 : new Double(Math.sqrt(vk / (double) (n - 1)))
                      : new Double(Math.sqrt(vk / (double) (n)));
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:11,代碼來源:SetFunction.java

示例3: norm

import java.lang.Math; //導入方法依賴的package包/類
public double norm(double[] v) {
    int nLen = v.length;
    double sum = 0;
    for (int i = 0; i < nLen; i++) {
        sum += Math.pow(v[i], 2.0);
    }
    return Math.sqrt(sum);
}
 
開發者ID:Driveron,項目名稱:Notes,代碼行數:9,代碼來源:Norm.java

示例4: j1

import java.lang.Math; //導入方法依賴的package包/類
/**
 * J 1 double.
 *
 * @param x a double value
 * @return the Bessel function of order 1 of the argument.
 * @throws ArithmeticException the arithmetic exception
 */

static public double j1(double x) throws ArithmeticException {

    double ax;
    double y;
    double ans1, ans2;

    if ((ax=Math.abs(x)) < 8.0) {
        y=x*x;
        ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1
                +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
        ans2=144725228442.0+y*(2300535178.0+y*(18583304.74
                +y*(99447.43394+y*(376.9991397+y*1.0))));
        return ans1/ans2;
    } else {
        double z=8.0/ax;
        double xx=ax-2.356194491;
        y=z*z;

        ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4
                +y*(0.2457520174e-5+y*(-0.240337019e-6))));
        ans2=0.04687499995+y*(-0.2002690873e-3
                +y*(0.8449199096e-5+y*(-0.88228987e-6
                +y*0.105787412e-6)));
        double ans=Math.sqrt(0.636619772/ax)*
                (Math.cos(xx)*ans1-z*Math.sin(xx)*ans2);
        if (x < 0.0) ans = -ans;
        return ans;
    }
}
 
開發者ID:RudyB,項目名稱:Optics-Simulator,代碼行數:38,代碼來源:SpecialFunction.java

示例5: decrypt

import java.lang.Math; //導入方法依賴的package包/類
/**
 * @param text (Geheimtext)
 * @param key (Schluessel)
 * 
 * @return algorithm() (Klartext)
 */
public String decrypt(String text, String key)
{
	
	currentAlphabet = myAlphabet.getAlphabet();
	String verified = verify(key, currentAlphabet);
	key = key.toLowerCase();
	
	if (verified != null){
		return verified;
	}
	int dimension = (int) Math.sqrt(key.length());
	int count = 0;
	while (text.length()%(dimension) != 0){
		text += currentAlphabet.charAt(0);
		count ++;
	}
	int [][] keyMatrix = Tools.makeMatrix(key, dimension, dimension, currentAlphabet);
	int [][] invKeyMatrix = MatrixTools.inverse(keyMatrix, currentAlphabet);
	System.out.println(Arrays.deepToString(keyMatrix));
	System.out.println(Arrays.deepToString(invKeyMatrix));
	
	String newText = algorithm(text, invKeyMatrix, currentAlphabet, dimension);
	System.out.println(newText);
	newText = newText.substring(0, newText.length()-count);
	return newText;
}
 
開發者ID:PSeminarKryptographie,項目名稱:MonkeyCrypt,代碼行數:33,代碼來源:Hill.java

示例6: completeState

import java.lang.Math; //導入方法依賴的package包/類
protected void completeState()
{
    double cx = 0, cy = 0;
    double mu20, mu11, mu02;
    double inv_m00 = 0.0;

    if( Math.abs(this.m00) > 0.00000001 )
    {
        inv_m00 = 1. / this.m00;
        cx = this.m10 * inv_m00;
        cy = this.m01 * inv_m00;
    }

    // mu20 = m20 - m10*cx
    mu20 = this.m20 - this.m10 * cx;
    // mu11 = m11 - m10*cy
    mu11 = this.m11 - this.m10 * cy;
    // mu02 = m02 - m01*cy
    mu02 = this.m02 - this.m01 * cy;

    this.mu20 = mu20;
    this.mu11 = mu11;
    this.mu02 = mu02;

    // mu30 = m30 - cx*(3*mu20 + cx*m10)
    this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
    mu11 += mu11;
    // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
    this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
    // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
    this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
    // mu03 = m03 - cy*(3*mu02 + cy*m01)
    this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);


    double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
    double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;

    this.nu20 = this.mu20*s2;
    this.nu11 = this.mu11*s2;
    this.nu02 = this.mu02*s2;
    this.nu30 = this.mu30*s3;
    this.nu21 = this.mu21*s3;
    this.nu12 = this.mu12*s3;
    this.nu03 = this.mu03*s3;

}
 
開發者ID:vulovicv23,項目名稱:opencv-documentscanner-android,代碼行數:48,代碼來源:Moments.java

示例7: setOmega

import java.lang.Math; //導入方法依賴的package包/類
/**
 * Set the omega parameter.
 * @param omega Omega parameter.
 */
public void setOmega(double omega) {
    this.omega = omega;
    this.constant = 2 * Math.sqrt(Math.pow(2, (1 / omega)) - 1) / sigma;
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:9,代碼來源:PearsonKernel.java

示例8: setSigma

import java.lang.Math; //導入方法依賴的package包/類
/**
 * Set the sigma parameter.
 * @param sigma Sigma parameter.
 */
public void setSigma(double sigma) {
    this.sigma = sigma;
    this.constant = 2 * Math.sqrt(Math.pow(2, (1 / omega)) - 1) / sigma;
}
 
開發者ID:takun2s,項目名稱:smile_1.5.0_java7,代碼行數:9,代碼來源:PearsonKernel.java


注:本文中的java.lang.Math.sqrt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。