如何获得复数值?

时间:2015-11-06 09:02:28

标签: 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'参数I获得了一个复杂的值,但是如何获得它的价值并将其提供给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

1 个答案:

答案 0 :(得分:1)

您的问题在于以下行:

  

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