简体   繁体   中英

How to represent this mathematical function in java

Please, can someone explain where my problem is? I was trying it really long and just can't get it done.

这是数学函数

I will be glad to hear an explanation of how to get this dependency. Thanks

    double a,s,k;
    int i;
    k=-2;
    s=-2*((1-x)/(1+x));
    a=-2*((1-x)/(1+x));
    i=3;
    while(i<10) {
        a=(k/(i))*a*a;
        s=s+a;
        i=i+2;
        System.out.println(a);
    }

Make certain that x is a double value. Here is one way to do it.

   public double fnc(double x) {
      double a, s, k;
      int i;
      k = -2.;
      s = 0;
      a = ((1 - x) / (1 + x));
      double aa = a * a;
      i = 1;
      while (i < 10) {
         // first time thru, a is power of 1
         s = s + ((k / i) * a); 
         // now a is power of 3, then 5, etc.
         a = a * aa; 
         i = i + 2;
      }
      return s;
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM