How to force Mathematica calculations in Reals domain only ?

Hi All

Maybe it’s a silly question for experienced users, but I’m rather new and I’m having troubles.
I need to know if there is a way to force Mathematica to work in the Reals domain.

For example, if I do

Plot[x^(1/3),{x,-10,10}]

I obtain a plot only for positive reals,
For negative ones Mathematica branches to a complex root and doesn’t plot it.

I know that in the past existed a package called RealOnly which did the job, but now it’s obsolete.

I tried several combinations of Assumptions and so on, but couldn’t figure out how to use them.

Many thanks

Stefano

This is curious:

Plot[Re[x^(1/3)], {x, -10, 10}]

Ah . . . It chooses one of the complex roots:

In[16]:= x /. Solve[x^3 == -10, x] // N

Out[16]= {1.07722 + 1.8658 I, -2.15443, 1.07722 - 1.8658 I}

Yes, that was my first try to solve the problem…

All, I think that the “Re[]” takes just the real part of the solution(s). Of course, negative real numbers have complex roots. If you want to see the real part of (each of) the solutions :

in:= Re[x /. Solve[x^3 == -10, x]] // N
out:= {1.07722, -2.15443, 1.07722}

As I recall, graphically, these are going to be where your curve “crosses” the axis.

A nice way to visualize all three:

in:= rePart = Re[x /. Solve[x^3 == -10, x]] // N
in: = imPart = Im[x /. Solve[x^3 == -10, x]] // N
in:= Partition[Riffle[rePart, imPart], 2]
in:= ListPlot[%]

Note, if you are looking for a way to “filter” and choose only those solutions that are Real (no imaginary part) you can add something that keeps only those solutions where the imaginary part is equal to zero.

Thanks.

What I would like to obtain, if it exists, is a general command that sets Mathematica to work only on the real branches of solutions.
In the old Derive program there is such a command : “Branch ? Real”

I know that I could arrange every plot or calculation for every single case, for example in the plot I mentioned I could do

Plot[Sign[x]*Abs[x]^(1/3), {x, -10, 10}]

and I would obtain my result.

But I’d like something general, so to set it up and go ahead without particular arrangements of the functions involved.

Hi,

What about

x /. Solve[x^3 == -10 && x \[Element] Reals, x] // N

You can use a similar idea to get your plot.

f := x /. Solve[x^3 == # && x \[Element] Reals, x] &

Then

Plot[f[y], {y, -10, 10}]

gives

I am not quite sure whether that is what you want though.

Cheers,

M.

Thanks, that sounds interesting. I will look into it

I understand that this is a little off-topic, but for some root operations you can use

In[1]:= ?Surd                                                                                                      
Surd[x, n] gives the real-valued n'th root of x.

In[2]:= ?CubeRoot                                                                       
CubeRoot[x] gives the real-valued cube root of x.

I think it’s on-topic. It still falls short of Stefano’s desire to have a general specification that keeps calculations in the Real branch. But CubeRoot does work for this. Surd however seems to generate the real roots when used directly, but not with Plot.

pcr = Plot[CubeRoot[x], {x, -10, 10}]

In[28]:= Surd[-10, 3]

Out[28]= -10^(1/3)
psurd = Plot[Surd[x, 3], {X, -10, 10}]

However,

psurd2 = Plot[y = Surd[x, 3]; y, {x, -10, 10}]

Well, at least there are some functions which behave like I expected.
Thanks

Actually Surd works fine in a plot. You used x as the variable in your plotted expression, but X in the plot range.

David, I think in your second example there is a type mistake : you used X instead of x as plot variable:

psurd = Plot[Surd[x, 3], {x, -10, 10}]

Thank you, John! That solves a mystery.

The basic mathematical issue is that the grand principles of algebra and analysis operate in the complex domain. Often, you have to reason through the complex domain to get a real answer. Any attempt to restrict Mathematica to operate in the real domain will generally impact its ability to break a problem down into subproblems. It is, however, often possible to ask for a real result:

In[20]:= Solve[x^3 == -10, Element[x, Reals]]

Out[20]= {{x -> Root[10 + #1^3 &, 1]}}

In[21]:= % // N

Out[21]= {{x -> -2.15443}}

The Root object is yet another way to express “the real cube root of -10”.

Yes, that is the answer. Thanks!

However, here you can download the obsolete add-on package which did the job I actually need. Works for version 6

At a certain point it says

"The RealOnly package is obsolete. Use instead functionality provided by \
Reduce[equations, variables, Reals] and by Assuming, Refine, and similar \
functions."

I tried several combinations of Reduce or Assuming without success :frowning:

Another way to look at it: for negative real numbers, there are several solutions coming from the complex roots. For instance, in the example above…

in:= solutions = Solve[x^3 == -10, x] // N
out:= {{x -> 1.07722 + 1.8658 I}, {x -> -2.15443}, {x -> 
   1.07722 - 1.8658 I}}

These solutions all have the same magnitude r[x]:

in:= Clear[r]
r[x_] := Sqrt[Re[x]^2 + Im[x]^2]
r@Values@solutions
out:= {{2.15443}, {2.15443}, {2.15443}}

If you don’t care to differentiate from among these solutions (though in my opinion, you’d be missing out on the best part!!) you could keep a single, real-valued magnitude:

in:= -1*Flatten@Union@%
out:= {-2.15443}

This yields a similar result as as plotting psurd[] above…

Plot[Piecewise[{{-1*Sqrt[Re[x]^2 + Im[x]^2]^(1/3), x < 0}, {x^(1/3), 
    x > 0}}], {x, -10, 10}]

I am sure my reply is off topic, but I have puzzled over a similar issue of reals and imaginary solutions.

In one problem, I have a messy integral whose integrand has no poles and is regular. Yet when I perform a numerical integration over some limits it will often throw off an imaginary solution. I have tried to suppress this behavior, because I don’t quite know what to do with the imaginary part of the solutions.

In the past, some respondents who answered my pleas for help said that if the imaginary part is small, they ignore it! Whoa. In some of my limits of integration, the imaginary part is as big as or larger than the real part. I am not familiar with Surd and will look into that, but otherwise, is this behavior in these integrals just user error on my part?

I am not quite a newby but lack depth in complex algebra and mathematical analysis.