MATLAB Answers

Symbolic expressions: abs(x^(1/3)) =?= abs(x)^(1/3)

19 views (last 30 days)
Thomas
Thomas on 17 Apr 2013
I have Matlab 2011b and when i do this:
>> x = sym('x')
x =
x
>> abs(x^(1/3))
ans =
abs(x)^(1/3)
then Matlab swaps the abs() and the ^(1/3).
Someone please correct me, but I would assume that x^(1/3) has three solutions, one real and two complex ones. (like here: http://en.wikipedia.org/wiki/Cubic_root#Real_numbers)
So putting the abs() around the root should yield exaxtly the one real(non-complex) solution (with multiplicity 3 if you want), because the magnitude of all three real and complex solutions should be identical.
However, by swapping abs() and the root to abs(x)^(1/3) i still get three solutions (one real, two complex again).
So where is my error or is it a bug?
Btw, if x is a lengthy expression itself it is annoying that i cannot make matlab evaluate this in the real numbers by putting an abs() around the root...

Answers (2)

the cyclist
the cyclist on 18 Apr 2013
I think you do have an error in thinking about this, but it is a subtle one.
First, and I think this is the important part, the expression
>> fx1 = abs(x).^(1/3);
and the expression
>> fx2 = abs(x.^(1/3));
are equal for all values of x. Agreed?
Note that there is nothing about root-finding of a function here. Those are just two expressions. x.^(1/3) does not have any "solutions". There is no equation there!
If you want to find roots before you do the absolute value, then do the root-finding on the equation first [x.^(1/3) - 1 == 0, or whatever], then do the absolute value.
Does that make sense?

  3 Comments

Thomas
Thomas on 18 Apr 2013
Hi and first of all thanks for answering.
>> are equal for all values of x. Agreed?
Okay, i just checked using a professional math book instead of wikipedia ;), i agree. The root function is indeed defined to be a function, i.e. to yield a unique value.
Let me describe my problem a little bit more detailed (please stick with me): I am calculating some rather complicated geometric relationship using symbolic variables to get an expression for a specific variable H i am interested in. At some point i have a lengthy cubic (in H) equation, that i solve for H using the solve function. Unfortunately some summands in the resulting equation for H look like
((3^(1/2)*i - 1)/2) * (<subexpression in ~10 variables>)^(1/3)
where the first part seems to be one of the complex solutions to x^(1/3)==1.
The first problem: The solution must be real... why do these complex roots appear in the first place? It is not incorrect, but it seems every time matlab solves a subexpression with a cube root it picks a random (and maybe complex) solution...
The second problem: I thought that i could take the abs() of the root to get the real result, however as stated this doesnt work since the abs is placed inside the root and the result is still complex (at least for some subexpressions). So how do i get matlab to give real roots? (for non-symbolic math the solution seems to be the nthroot function, however it does not work with symbols)
bym
bym on 18 Apr 2013
maybe you can start off by declaring your variables to be real e.g.
syms x y z real
Thomas
Thomas on 19 Apr 2013
Thanks for the idea. I already did this, however it does not solve the problem, since result is still complex.

Sign in to comment.


Ahmed A. Selman
Ahmed A. Selman on 19 Apr 2013
Edited: Ahmed A. Selman on 19 Apr 2013
Some times we get confused between mathematics and programming, it is an often thing. Yet, mathematics means logic, programs try to reason that logic with numbers to us. So in mathematics, there's no difference between:
abs(-2^(1/3)) = 1.2599
(abs(-2)) ^(1/3) = 1.2599
assuming that the function abs is meaningless for positive real arguments. Now, let's elaborate more:
y= (-2)^(1/3)
y= 0.6300 + 1.0911i
no matter how many times I tried that with Matlab it gives the same, i.e., no random numbers here. One more thing:
abs(y)= 1.2599
The same as above!
Would Matlab be having a problem if it said so? I don't think that.
However, if you tried, e.g.,
syms x z
y=abs(x^z)
y=
abs(x^z)
leaving mathematical possibilities for any values of z to be reasonably usable.

  1 Comment

Thomas
Thomas on 19 Apr 2013
Take a look at:
  • (8)^(1/3) ----> 2 (good)
  • (-8)^(1/3) ----> 1.0000 + 1.7321i (would like -2 more as an answer...)
So i can use
  • nthroot(-8,3) ----> -2 (better now)
However, nthroot doesn't work for symbolic expressions. But as i have seen now, matlab 2013 offers a function "surd" that seems to do what i need - unfortunately i don't have M2013 yet...

Sign in to comment.


Translated by