Mathematica Mathematica and complex numbers

AI Thread Summary
The discussion revolves around solving the equation x + I y = Sqrt[a + I b] for variables a and b in terms of x and y using Mathematica. Initial attempts using the Solve function resulted in errors, indicating that the equations may not yield solutions for all variables. Participants noted that Mathematica assumes variables are complex unless specified otherwise. Suggestions included using the Assuming function to set real-valued assumptions for the variables, as well as employing the Reduce function for better results. There was also a discussion about the limitations of the Solve function and the potential effectiveness of FullSimplify in this context. Participants shared their experiences with these functions, indicating mixed results and the need for further experimentation with assumptions to achieve the desired outcomes.
Phrak
Messages
4,266
Reaction score
7
I can't come up with the code to solve for a and b in terms of x and y.

Code:
x + I y = Sqrt[a + I b]

Code:
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}}
 
Physics news on Phys.org
It's assuming all of the variables are complex-valued. You need to tell it they are real-valued with an Assumptions clause.
 
Hurkyl said:
It's assuming all of the variables are complex-valued. You need to tell it they are real-valued with an Assumptions clause.

Assumptions is an unknow option to Solve, so I tried

Code:
Element[{a, b, x, y}, Reals]
Solve[x + I y == Sqrt[a + I b], {a, b}]
obtaining
Code:
(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}}
 
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:
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:
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.
 
Hurkyl said:
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.

Oh! "Assuming". I don't know Assuming. I assumed :redface: you meant Assumptions. I'll try it.
 
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}]
 
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!
 
  • #10
Thanks Dale. I've tried some variations with mixed results. Suprisingly, manually simplifying to

Code:
Reduce[{ a + I b == (x + I y)^2, {x, y, a, b} \[Element] Reals}, {a, 
  b}]
yields the result
Code:
(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:
{x, y, a, b} \[Element] Reals
works well.

I'm still playing with Assuming, Hurkyl.
 
Last edited:
  • #11
Sometimes, FullSimplfy'ing results helps. I suspect it will help here.
 
  • #12
Hurkyl said:
Sometimes, FullSimplfy'ing results helps. I suspect it will help here.
Yes, and FullSimplify definitely allows you to set assumptions.
 

Similar threads

Replies
1
Views
2K
Replies
13
Views
2K
Replies
1
Views
1K
Replies
19
Views
2K
Replies
1
Views
2K
Replies
5
Views
3K
Replies
4
Views
2K
Replies
1
Views
2K
Back
Top