Mathematica and complex numbers

In summary: I think it might be because Mathematica expects the first equation to give the real and imaginary parts (and assumes they are both the same), but the second equation needs the imaginary part to be zero for it to work.I've tried some variations with mixed results. Suprisingly, manually simplifying to Reduce[{ a + I b == (x + I y)^2, {x, y, a, b}...}, {a, b}] didn't work for some reason. I think it might be because Mathematica expects the first equation to give the real and imaginary parts (and assumes they are both the
  • #1
Phrak
4,267
6
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
  • #2
It's assuming all of the variables are complex-valued. You need to tell it they are real-valued with an Assumptions clause.
 
  • #3
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}}
 
  • #4
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:
  • #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:
  • #6
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.
 
  • #7
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.
 
  • #8
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}]
 
  • #9
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.
 

Related to Mathematica and complex numbers

What is Mathematica and how does it handle complex numbers?

Mathematica is a software program used for mathematical computation and data visualization. It has a built-in function for handling complex numbers, which are numbers that have both a real and imaginary component. This function allows for arithmetic operations, plotting, and other manipulations with complex numbers.

How can I input complex numbers in Mathematica?

To input a complex number in Mathematica, you can use the syntax "a + b*I" where "a" and "b" represent the real and imaginary parts, respectively. For example, to input the complex number 2 + 3i, you would type "2 + 3*I".

Does Mathematica have functions specifically for working with complex numbers?

Yes, Mathematica has a variety of built-in functions that are specifically designed for working with complex numbers. These include functions for finding the magnitude, phase, and conjugate of a complex number, as well as functions for performing complex trigonometric and exponential operations.

Can I plot complex numbers in Mathematica?

Yes, Mathematica has a function called "ComplexPlot" that allows you to plot complex numbers on a complex plane. This can be useful for visualizing the behavior of complex functions, as well as for understanding the geometric properties of complex numbers.

Can Mathematica solve equations involving complex numbers?

Yes, Mathematica has a powerful equation solving function called "Solve" that can handle equations with complex numbers. It can also handle systems of equations with both real and complex variables. Additionally, there are other specialized functions for solving specific types of equations involving complex numbers, such as "NSolve" for numerical solutions and "Reduce" for finding algebraic solutions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
550
  • MATLAB, Maple, Mathematica, LaTeX
Replies
19
Views
581
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
419
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top