Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica and complex numbers

  1. Jan 17, 2010 #1
    I can't come up with the code to solve for a and b in terms of x and y.

    Code (Text):
    x + I y = Sqrt[a + I b]
    Code (Text):
    In[84]:= Clear["Global`*"]
    Solve[x + I y == Sqrt[a + I b], {a, b}]

    During evaluation of In[84]:= Solve::svars:
    Equations may not give solutions for all "solve" variables. >>

    Out[85]= {{a -> -I b + x^2 + 2 I x y - y^2}}
     
  2. jcsd
  3. Jan 17, 2010 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    It's assuming all of the variables are complex-valued. You need to tell it they are real-valued with an Assumptions clause.
     
  4. Jan 17, 2010 #3
    Assumptions is an unknow option to Solve, so I tried

    Code (Text):
    Element[{a, b, x, y}, Reals]
    Solve[x + I y == Sqrt[a + I b], {a, b}]
     
    obtaining
    Code (Text):

    (a | b | c | d) \[Element] Reals

    During evaluation of In[34]:= Solve::svars:
    Equations may not give solutions for all "solve" variables. >>

    {{a -> -I b + x^2 + 2 I x y - y^2}}
     
  5. Jan 17, 2010 #4

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Solve doesn't deal with assumptions? :frown:

    Try wrapping the whole thing in an Assuming function then (I think that's the right name), to set the assumptions.


    I think the Element command you used is just a test (boolean-valued expression of the variables a,b,c,d) -- it has to be added to the equation to be solved or made into an assumption or something to have an effect.


    There might be some way to tell Mathematica that a variable is real in the way you tried with Element (i.e. to make a global assumption) or an annotation you can put on the variable itself, but I don't know it.
     
    Last edited: Jan 18, 2010
  6. Jan 18, 2010 #5
    I tried doing what you had in mind, as far as mathematica would allow them. I think you're right about the Element function. It doesn't seem to have an effect. I think that Solve is not primitive enough. It uses the more primative InverseFunction. I don't know how to apply InverseFunction.

    My guess is that you don't have mathematica but have studied it. I think it's made for someone like you. The single data-type in mathematica is an acyclic directed tree. Interesting... Why? The terminating nodes are the more familiar sorts of data types such as real, integer, string. So the terminating nodes are things that don't act on other things. The non-terminating nodes are functions that act on it's branches. (Interestingly, transcendental numbers like Pi are something else. I haven't discovered what.) All nodes are a common class called symbol. This is the core language. There are other elements like a pre-reader.

    The syntax of mathematica, and the more primitive functions will allow you to create your own data syntax and algebras. If you want things other than acycle directed trees, you can probably make them out of trees.

    Anyway, I'm still asking "what is mathematics, and what is doing mathematics?" You could probably get a lot further than me if you bought a copy--assuming you don't already have a copy, of course.
     
    Last edited: Jan 18, 2010
  7. Jan 18, 2010 #6

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I use it at work, but don't have it at home. I use it enough to be able to do/know where to find these sorts of things, but I've never actually "studied" it and have nowhere near the depth of knowledge as I do a language like C++.

    I'm sure I've had this problem before and worked through it -- I thought I had used the Assuming function to do it. But maybe I just wound up working out how to split it into real and imaginary parts? e.g. using FullSimplify on Re[expr] with the appropriate assumptions clauses.
     
  8. Jan 18, 2010 #7
    Oh! "Assuming". I don't know Assuming. I assumed :redface: you meant Assumptions. I'll try it.
     
  9. Jan 18, 2010 #8

    Dale

    Staff: Mentor

    You will probably have better luck with Reduce:

    Reduce[{x + I y == Sqrt[a + I b], Im[x] == 0, Im[y] == 0, Im[a] == 0,
    Im == 0}, {a, b}]

    or

    Reduce[{x + I y == Sqrt[a + I b], x \[Element] Reals,
    y \[Element] Reals, a \[Element] Reals, b \[Element] Reals}, {a, b}]
     
  10. Jan 18, 2010 #9

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Hrm. I've had good luck with Reduce and bad luck with Reduce. I thought it wouldn't work here -- but I certainly don't have enough experience to be sure without trying!
     
  11. Jan 19, 2010 #10
    Thanks Dale. I've tried some variations with mixed results. Suprisingly, manually simplifying to

    Code (Text):
    Reduce[{ a + I b == (x + I y)^2, {x, y, a, b} \[Element] Reals}, {a,
      b}]
    yields the result
    Code (Text):
    (x | y) \[Element] Reals && a == x^2 - y^2 &&
     b == -I (-a + x^2 + 2 I x y - y^2)
    where 'b remains unresolved,
    although the contained expression
    Code (Text):
    {x, y, a, b} \[Element] Reals
    works well.

    I'm still playing with Assuming, Hurkyl.
     
    Last edited: Jan 19, 2010
  12. Jan 19, 2010 #11

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Sometimes, FullSimplfy'ing results helps. I suspect it will help here.
     
  13. Jan 20, 2010 #12

    Dale

    Staff: Mentor

    Yes, and FullSimplify definitely allows you to set assumptions.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica and complex numbers
Loading...