0

I have A function Func(x) which returns a complex number.

And I need to calculate Integral of I/Func(E^(I*x)) where x is from Pi/3 to Pi/2.

How can i do that in Java?

Michael
  • 32,527
  • 49
  • 210
  • 370
Kostya
  • 119
  • 6
  • 1
    Can you add some part of your code whatever you have progressed till now – Charles Stevens May 05 '15 at 11:56
  • 3
    Have you tried something? If you did, paste your code, and tell us where you have the error. If you didn't ... try it first, and then come to ask for your errors. We don't do Homework. Try to read the tour to do good questions --> http://stackoverflow.com/tour – Shudy May 05 '15 at 11:56
  • Have a look at [Apache Commons Math](http://commons.apache.org/proper/commons-math/) – LittlePanda May 05 '15 at 11:59
  • For the sake of clarity, are you using `I` as the square root of -1 and `E` as the base of the natural logarithm? Those are generally denoted as lower case `i` or `j` in the case of the square root of -1 and lower case `e` in the case of the base of the natural logarithm. Also, is `x` a real number or is it a complex number? If it's complex is `Func` also an analytic function? – andand May 05 '15 at 14:38
  • @andand Not necessarily when the programming language recommends that constants be in all caps. In this case [E](https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#E) (with PI right below) and [I](http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/complex/Complex.html#I). – Teepeemm May 05 '15 at 15:48
  • If you need an exact, symbolic result -- if you only have to solve this for a known value or values of `Func`, solve it in some symbolic computation system (e.g. [Maxima](http://maxima.sourceforge.net) or [Sympy](http://sympy.org)). If you need to solve this for a variable `Func`, my first advice is to give up Java and work entirely in Maxima or Sympy. My second advice is to invent some glue code to enable a Java program to talk to Maxima or Sympy. I know it can be done for Maxima, but it is somewhat painful. – Robert Dodier May 05 '15 at 16:17
  • 1
    If you need a numerical result -- since the integral is actually an integral of a single real variable `x`, you can separate the integrand into real and imaginary parts and integrate those separately and then take your result as integral(real part) + I*integral(imaginary part). This is much, much simpler than trying to integrate symbolic stuff into Java .... – Robert Dodier May 05 '15 at 16:20
  • @Teepeemm Understood with Java... but then if that were Java code, I don't think `^` would be the correct operator in this context. – andand May 05 '15 at 16:59

1 Answers1

0

Apache Commons library provide a good support for handling complex numbers. Have a look at - Apache commons complex

Raúl
  • 1,542
  • 4
  • 24
  • 37
  • I understood Apache Commons's Complex Numbers ,problem is I wasn't able to understand it Integration's – Kostya May 05 '15 at 12:17
  • 2
    In that case, you should try it out first, then post specific issue you face - if any. – Raúl May 05 '15 at 12:18
  • Apache Commons Math documentation says its quadrature functions are only for real functions of 1 variable. – Robert Dodier May 05 '15 at 16:11
  • I realize now that OP's integral is actually an integral of a real variable, so Apache Commons Math is indeed applicable (if OP is looking for a numerical approximation). – Robert Dodier May 05 '15 at 16:21