java - 如何获取复数值?

标签 java complex-numbers

这是我的代码...

import java.io.IOException;
import java.util.Scanner;
public class MyFirstClass {

    private static Scanner scanner = new Scanner( System.in );

    public static void main(String[] args) throws IOException {



        System.out.println("Enter the value of Thickness of diaphram ");
        double hd = scanner.nextDouble();

        System.out.println("Enter the value of side length of diaphram ");
        double ad = scanner.nextDouble();

        System.out.println("Enter the value of hole fraction of diaphram ");
        double kh = scanner.nextDouble();

        System.out.println("Enter the value of overlapping Area of diaphram ");
        double A = scanner.nextDouble();

        System.out.println("Enter the value of air  gap of diaphr`enter code here`am ");
        double haint = scanner.nextDouble();

        double  Ed= (160* Math.pow(10, 9));
        double vd=(0.2);
        int rhod=2300;
        double Eo=  8.854*Math.pow(10,-12);
        double pi = (3.142857142857412857412857412);



        double Fres = (hd/(2*pi*(Math.pow(ad, 2)))*(Math.sqrt((Ed/(0.02436*((1-(Math.pow(vd,2)))*rhod))))));



        double D =((Ed *(Math.pow(hd,3))) /(12*(1- (Math.pow(vd, 2)))));
        double Vb = 5.225 *(Math.sqrt((Ed*(Math.pow(hd, 3))*(Math.pow(haint, 3)))/((1-(Math.pow(vd, 2)))*Eo*(Math.pow(ad, 4)))));
        double M = ((0.00203*Eo*(Math.pow(ad, 4))*(Math.pow(Vb, 2))) / (4*D));
        double haeff = (haint/3)*(1+ 2* Math.cos((.33* (Math.acos((1 - ((27*M)))/(Math.pow(haint, 3)))))));
        double Cm=Math.abs(((Eo*(1-kh)*A)/(haeff)));

        double Se=((0.09274*(Math.pow(ad,2)))*(Math.sqrt(1-(Math.pow(vd, 2))))*(Math.sqrt(haint)))/((Math.sqrt(Ed))*(Math.pow(hd, 1.5))*(Math.sqrt(Eo)));       

                System.out.println("Fres = "+Fres);

                System.out.println("Capacitance = "+Cm);
                System.out.println("Sensitivity = "+Se);

    }
}

这里我没有得到“Cm”参数的输出,因为它给出了“NaN”。在“haeff”参数中,我获得了一个复数值,但如何获取其值并将其输入“Cm”参数中。

这是 MATLAB 代码及其答案......

clc;
clear all;
hd=input('Thickness of the diameter = ');
ad= input('side length of the diaphram=');
kh= input('hole fraction= ');
A= input('Overlapping area=');
haint= input('Initial air gap between diaphram and back plate=');
Ed= 160* (10^9);
vd=.2;
rhod=2300;
Eo= 8.854 * 10^-12;
% --------------Resonant Frequancy Start line---------------
Fres = (hd/(2*pi*(ad^2)))*(sqrt(Ed/(0.02436*(1-(vd^2))*rhod))) %resonant freq
% --------------Resonant Frequancy End line---------------

% --------------Capacitance Start Line ---------------------
D = (Ed *(hd^3)) /(12*(1- (vd^2)));
Vb = 5.225 *sqrt((Ed*(hd^3)*(haint^3))/((1-(vd^2))*Eo*(ad^4)));
M = ((0.00203*Eo*(ad^4)*(Vb^2)) / (4*D))
haeff =  (haint/3)*(1+ 2* cos(.33* acos(1 - ((27*M)/(haint^3)))))

Cm=abs((Eo*(1-kh)*A)/(haeff))%Capacitance 
% -----------------Capacitance End Line-------------------

% --------------Sensitivity Start Line ---------------------
Se=(0.09274*(ad^2)*sqrt(1-(vd^2))*sqrt(haint))/((sqrt(Ed)*(hd^1.5))*(sqrt(Eo)))

其答案如下

Thickness of the diameter = 2.3e-6
side length of the diaphram=2e-6
hole fraction= .8
Overlapping area=3e-6
Initial air gap between diaphram and back plate=.8

Fres =

   4.9913e+09


M =

    0.0851


haeff =

   0.5946 + 0.3110i


Cm =

   7.9169e-18


Se =

   7.8304e-05

最佳答案

您的问题在于以下行:

double haeff = (haint/3)(1+ 2 Math.cos((.33* (Math.acos((1 - ((27*M)))/(Math.pow(haint, 3)))))));

...以下操作:

(1 - ((27*M)))/(Math.pow(haint, 3))

...可能返回不在[-1, +1]范围内的负数(我用小整数测试,它返回-4)

返回以下代码段中的函数Math.acos:

Math.acos((1 - ((27*M)))/(Math.pow(haint, 3)))

...返回NAN(简单三角函数)。因此将 haeff 的值渲染为 NAN,结果

double Cm=Math.abs(((Eo*(1-kh)*A)/(haeff)));

...使用 haeff 的值将是 NAN

关于java - 如何获取复数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33563004/

相关文章:

java - 在学习 Swing 之前必须先学习 AWT 吗?

java - 在 ServletRequest 到达 Servlet/Filter 后从中删除查询字符串

c++ - inner_product 和复 vector

java - 家庭作业帮助 Pt2(数学复杂课)

c++ - 计算复数的乘法

java - 我如何根据非唯一键插入或更新 jpa 实体?

java - 在 Cordova 中单击 html 按钮时启动新 Activity

c++ - 在C++中平均一组复数的正确方法是什么?

c++ - 如何在 C++ 中使用复数 "i"

java - 如何从库项目调用主项目中的类/方法?