Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Integrate[m^2/((x - m^2)^2 + y^2), m]

mathematica gives me a complex-valued reuslt, but maple 17 gives me what I want.

maple result

I tried using assumptions, but it doesn't work.

In MMA, is there a general way to do integrations in real domains, just like maple.

Can this wrap bulit-in command proposed by Todd Gayley (see: http://stackoverflow.com/questions/4198961/what-is-in-your-mathematica-tool-bag ) do the trick?

Message[args___] := Block[{$inMsg = True, result},
    "some code here";
    result = Message[args];
    "some code here";
    result] /; ! TrueQ[$inMsg]

Perhaps the reason for the complex-valude result is the invovled power calculation during the integration, so maybe what I really need is a general way to do symbolic power calculation in real domains?

ComplexExpand doesn't work as in the post integration on real domain only!.

thanks :)

share|improve this question
    
@Artes Integrate[m^2/((1 - m^2)^2 + 1), {m, 0, 1}], Maple 17 gives 1/8 Sqrt[-1 + Sqrt[ 2]] (2 (2 + Sqrt[2]) ArcTan[Sqrt[2 (1 + Sqrt[2])]] + Sqrt[2] Log[5 + 4 Sqrt[2] - 2 Sqrt[2 (7 + 5 Sqrt[2])]]) –  chyaong May 13 '13 at 11:31
    
This issue is more general. Take a look at this answer: mathematica.stackexchange.com/questions/23080/…. One might get rid of unwanted imaginary part working with appropriate assumptions, see what happens for special values x and y, e.g. Integrate[m^2/((1 - m^2)^2 + 1), {m, 0, 1}] –  Artes May 13 '13 at 11:34
    
@chyanog You can map all ComplexExpand i.e. ComplexExpand //@ Integrate[m^2/((1 - m^2)^2 + 1), {m, 0, 1}], then you'll see how one could proceed to remove apparently immaginary result. –  Artes May 13 '13 at 11:40
    
@Artes and chyanog. These are not what I want. Please, normally, given a integration problem, you don't do some tests using specific values as what Artes does. If I have time to do these tests, why don't I using maple's results directly? Please no tests, just want a general way to do symbolic indefinite integration. Anyway, thanks. –  pengfei_guo May 14 '13 at 1:26
2  
@pengfei_guo Maple results and Mathematica ones can be equivalent under some assumptions, it doesn't matter that they are apparently different. If you analyze carefully the link I gave above you'll probably better understand the problem. However demonstrating that the both results are equivalent may depend on case by case basis. –  Artes May 14 '13 at 1:36

2 Answers 2

It is not quite clear, what do you you want to get out of the answer.

Would you like to compare Maple and Mma and understand, which one is better ?

Or would you like to understand the alternative forms of taking this integral?

Or the reason, why the results of Marple and Mma are different?

Or transform the Mma result in terms of xand y?

Or, finally, transform the Mma result in terms of xand y, such that it does ot contain imaginary unit?

If your question concerns any comparison Maple with Mma, the point is that they differently understand the expression complexity. So Mma returns the result (demonstrated by Bob above) that seems it more concise, and it, inded, looks shorter than that of Maple (you show above).

The second question is what do you intend to do with this result. If you, say, only need to plot it in Mma (or to do something comparable), the Mma result is perfect, do, plot it.

However, you might want to further transform it, and may, say, differently treat different terms. In such a case you may need to have it in terms of xand y, such that it does not contain imaginary unit.

I choose this possibility, since the task seems me personally challenging. So my response below is for this special case. If you do not need it, disregard it.

So, let me first make the integral a bit differently with respect to Bobs approach, by representing it in a more canonical form. Let us introduce z=m^2and integrate over z:

 expr1 = Integrate[z/((z + x)^2 + y^2)*1/(2 Sqrt[z]), z, 
   Assumptions -> {z > 0, x ∈ Reals, y ∈ Reals}] /. 
  Sqrt[z] -> m

(*  1/2 (((I x + y) ArcTan[m/Sqrt[x - I y]])/(
   Sqrt[x - I y] y) + ((-I x + y) ArcTan[m/Sqrt[x + I y]])/(
   Sqrt[x + I y] y))    *)

Now let us make a replacement of variables:

expr2 = expr1 /. {1/Sqrt[x + I y] -> 
    1/r*Exp[-I f/2], -I x + y -> -I r^2 Exp[I f], 
   1/Sqrt[x - I y] -> 1/r*Exp[I f/2], I x + y -> I r^2 Exp[-I f]}

(*   1/2 (-((I E^((I f)/2) r ArcTan[(E^(-((I f)/2)) m)/r])/y) + (
   I E^(-((I f)/2)) r ArcTan[(E^((I f)/2) m)/r])/y)   *)

and ComplexExpand the result

expr3 = ComplexExpand[expr2]

I do not show the result, since it is rather long, you may obtain it, and just looking at it you will find expressions like Arg[1 - (I E^(-((I f)/2)) m)/r]. They can be replaced by ArcTans:

  expr4 = expr3 /. {Arg[
     1 - (I E^(-((I f)/2)) m)/
      r] -> -ArcTan[(( m Cos[f/2])/r)/(1 - (m Sin[f/2])/r)], 
   Arg[1 + (I E^(-((I f)/2)) m)/r] -> 
    ArcTan[((m Cos[f/2])/r)/(1 + (m Sin[f/2])/r)], 
   Arg[1 - (I E^((I f)/2) m)/
      r] -> -ArcTan[(( m Cos[f/2])/r)/(1 + (m Sin[f/2])/r)], 
   Arg[1 + (I E^((I f)/2) m)/r] -> 
    ArcTan[((m Cos[f/2])/r)/(1 - (m Sin[f/2])/r)]}

(*
(r Cos[f/2] Log[(m^2 Cos[f/2]^2)/r^2 + (1 - (m Sin[f/2])/r)^2])/(
 4 y) - (r Cos[f/
   2] Log[(m^2 Cos[f/2]^2)/r^2 + (1 + (m Sin[f/2])/r)^2])/(4 y) + (
 r ArcTan[(m Cos[f/2])/(r (1 - (m Sin[f/2])/r))] Sin[f/2])/(2 y) + (
 r ArcTan[(m Cos[f/2])/(r (1 + (m Sin[f/2])/r))] Sin[f/2])/(2 y)
*)

The resulting expression is Real. It is only left to replace the amplitude and phase in it:

 expr5 = expr4 /. {r -> (x^2 + y^2)^(1/4), f -> ArcTan[y/x]}

(*     ((x^2 + y^2)^(1/4)
   Cos[1/2 ArcTan[y/x]] Log[(m^2 Cos[1/2 ArcTan[y/x]]^2)/Sqrt[
    x^2 + y^2] + (1 - (m Sin[1/2 ArcTan[y/x]])/(x^2 + y^2)^(
      1/4))^2])/(
 4 y) - ((x^2 + y^2)^(1/4)
   Cos[1/2 ArcTan[y/x]] Log[(m^2 Cos[1/2 ArcTan[y/x]]^2)/Sqrt[
    x^2 + y^2] + (1 + (m Sin[1/2 ArcTan[y/x]])/(x^2 + y^2)^(
      1/4))^2])/(
 4 y) + ((x^2 + y^2)^(1/4)
   ArcTan[(m Cos[1/2 ArcTan[y/x]])/((x^2 + y^2)^(
    1/4) (1 - (m Sin[1/2 ArcTan[y/x]])/(x^2 + y^2)^(1/4)))] Sin[
   1/2 ArcTan[y/x]])/(
 2 y) + ((x^2 + y^2)^(1/4)
   ArcTan[(m Cos[1/2 ArcTan[y/x]])/((x^2 + y^2)^(
    1/4) (1 + (m Sin[1/2 ArcTan[y/x]])/(x^2 + y^2)^(1/4)))] Sin[
   1/2 ArcTan[y/x]])/(2 y)
*)

That's it. It may by done still a bit simpler:

 FullSimplify[expr5, {m ∈ Reals, x ∈ Reals, 
  y ∈ Reals}]

(*   (1/(4 y))(x^2 + y^2)^(
 1/4) (Cos[
     1/2 ArcTan[y/x]] (Log[
       m^2 + Sqrt[x^2 + y^2] - 
        2 m (x^2 + y^2)^(1/4) Sin[1/2 ArcTan[y/x]]] - 
      Log[m^2 + Sqrt[x^2 + y^2] + 
        2 m (x^2 + y^2)^(1/4) Sin[1/2 ArcTan[y/x]]]) + 
   2 (ArcTan[(
       m Cos[1/2 ArcTan[y/x]])/((x^2 + y^2)^(1/4) - 
        m Sin[1/2 ArcTan[y/x]])] + 
      ArcTan[(m Cos[1/2 ArcTan[y/x]])/((x^2 + y^2)^(1/4) + 
        m Sin[1/2 ArcTan[y/x]])]) Sin[1/2 ArcTan[y/x]])
*)

Now that is the end. If it looks a bit different to what you see in Maple, it should be for the same reason.

enter image description here

Note that tan^-1in the picture above means ArcTan. If it is what you are looking for, be carefull with the replacements like Arg[1 - (I E^(-((I f)/2)) m)/ r] -> -ArcTan[(( m Cos[f/2])/r)/(1 - (m Sin[f/2])/r)]. In some cases they may introduce an error, check them. I did not. Have fun!

Later Edit: In responce to the notes of Michael E2:

Yes, Michael, you are right, I mixed up the sign in the integral. Then the integral is:

expr1 = Integrate[z/((z - x)^2 + y^2)*1/(2 Sqrt[z]), z, 
   Assumptions -> {z > 0, x \[Element] Reals, y \[Element] Reals}] /. 
  Sqrt[z] -> m

The further operations with the sign "-" are the same as with "+" up to (including) expr3. Then one can do the following. These are the replacement rules:

    rules = {Arg[
     1 - (E^((I f)/2) m)/
      r] -> -ArcTan[(( m Sin[f/2])/r)/(1 - (m Cos[f/2])/r)], 
   Arg[1 + (E^((I f)/2) m)/r] -> 
    ArcTan[((m Sin[f/2])/r)/(1 + (m Cos[f/2])/r)], 
   Arg[1 - (E^(-((I f)/2)) m)/r] -> 
    ArcTan[(( m Sin[f/2])/r)/(1 - (m Cos[f/2])/r)], 
   Arg[1 + (E^(-((I f)/2)) m)/
      r] -> -ArcTan[(( m Sin[f/2])/r)/(1 + (m Cos[f/2])/r)], 
   Cos[1/2 Arg[x + I y]] -> Cos[1/2*ArcTan[y/x]], 
   Cos[1/2 Arg[x - I y]] -> Cos[1/2*ArcTan[y/x]], 
   Sin[1/2 Arg[x - I y]] -> -Sin[1/2 ArcTan[y/x]], 
   Sin[1/2 Arg[x + I y]] -> Sin[1/2 ArcTan[y/x]]};

In these rules I only accounted for the first quadrant x>0, y>0. In general case one can everywhere in these and later rules write ArcTan[b,a]instead of the ArcTan[a/b]. But then results are not simplified to such a short expression, as we see in the end. Now the substitutions work as follows:

 expr4 = expr3 /. rules;
expr5 = expr4 /. {r -> (x^2 + y^2)^(1/4), f -> ArcTan[y/x]};
Simplify[expr5, {x > 0, y > 0, m > 0}]

The result is as follows:

(*  
(1/(4 y))(x^2 + y^2)^(
 1/4) (2 ArcTan[(
     m Sin[1/2 ArcTan[y/x]])/((x^2 + y^2)^(1/4) - 
      m Cos[1/2 ArcTan[y/x]])] Cos[1/2 ArcTan[y/x]] + 
   2 ArcTan[(
     m Sin[1/2 ArcTan[y/x]])/((x^2 + y^2)^(1/4) + 
      m Cos[1/2 ArcTan[y/x]])] Cos[1/2 ArcTan[y/x]] + 
   Log[(m^2 + Sqrt[x^2 + y^2] - 
      2 m (x^2 + y^2)^(1/4) Cos[1/2 ArcTan[y/x]])/(
     m^2 + Sqrt[x^2 + y^2] + 
      2 m (x^2 + y^2)^(1/4) Cos[1/2 ArcTan[y/x]])] Sin[
     1/2 ArcTan[y/x]])
*)

Generally, I think that after the direction is shown, the OP should do details and check for possible errors hiself.

share|improve this answer
    
I think the replacement yields an error when the real of the argument to Arg is negative. (Certainly the ranges imply an error.) I did something similar, albeit not as elegantly as you, but decided it was an unsatisfactory answer to the general question of how to keep an integral in the reals. I approached Arg via ArcCos and Sign[Re[..]]. Then I decided the Mma answer is superior and simpler anyway. With respect to the OP's question, I learned real-only integration as a youngster, but perhaps I'm outgrowing it. :) –  Michael E2 Aug 2 at 21:37
    
@Michael E2 Yes, that's what I meant with the last sentence in my answer. I simply think that the author may not be interested too much in transformations like that. In fact to avoid the error one should use ArcTan[x,y]instead of ArcTan[y/x]. But then the result looks less "traditional". So, my answer as it is, is only valid for the first qudrant x>0 y>0. –  Alexei Boulbitch Aug 3 at 9:22
    
I didn't have Mma yesterday -- today I noticed that your integrand differs slightly from the OP's. Undoing the substitution, it is equivalent to m^2/((x + m^2)^2 + y^2) whereas the OP has a minus between the x and m^2. Essentially the difference is the same as changing x to -x, which is not an important difference at all. (Also, the ArcTan[y/x] will be valid for x > 0, y <= 0, too.) +1. –  Michael E2 Aug 3 at 12:51
    
@Michael E2 Have a look to the later edit. –  Alexei Boulbitch Aug 3 at 13:40

For Element[{m, x, y}, Reals] the function is real; however, numerical noise can result in an imaginary artifact that can be removed with Chop

int[m_, x_, y_] = Assuming[{Element[{m, x, y}, Reals]},
  Integrate[m^2/((x - m^2)^2 + y^2), m] //
   FullSimplify]

(I*(Sqrt[-x - I*y]*ArcTan[m/Sqrt[-x - I*y]] - Sqrt[-x + I*y]*ArcTan[m/Sqrt[-x + I*y]]))/(2*y)

(int @@@ RandomReal[{-2, 2}, {40, 3}]) // Chop[#, 10^-15] &

{-0.0254214, -0.0710269, 0.017061, -0.159841, 0.00667301, 0.134012, 0.0549759, -0.00119414, -4.68272, -0.797005, -0.0151467, 0.0737341, -0.120778, 0.00454359, -0.870848, -0.0339835, -3.453, 0.465008, -9.04711, -9.02031, 0.000540718, 0.0492567, 0.282303, 0.0357629, -0.155331, -0.482013, 0.0955548, 0.0110472, -0.0248232, -0.126987, 0.268351, 0.0481008, -0.132282, 0.0273012, 0.000381937, -0.21833, -0.00260406, 2.10403, 0.234028, 0.00998243}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.