Wolfram Mathematica How to Make X Become X Again

Message Boards Bulletin Boards

31767 Views

|

34 Replies

|

24 Full Likes

|

Hello All

Maybe information technology'south a giddy question for experienced users, merely I'yard 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,-x,ten}]                          

I obtain a plot only for positive reals, For negative ones Mathematica branches to a circuitous root and doesn't plot information technology.

I know that in the past existed a package chosen RealOnly which did the chore, merely now it's obsolete.

I tried several combinations of Assumptions and then on, only couldn't figure out how to use them.

Many thanks

Stefano

  • Reply
  • |
  • Flag

This is curious:

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

enter image description here

  • Reply
  • |
  • Flag

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

In[16]:= ten /. Solve[x^three == -10, 10] // N  Out[16]= {1.07722 + 1.8658 I, -2.15443, 1.07722 - ane.8658 I}                          
  • Reply
  • |
  • Flag

Yes, that was my beginning try to solve the problem......

  • Reply
  • |
  • Flag

All, I think that the "Re[]" takes simply the existent role of the solution(due south). Of class, negative real numbers have complex roots. If y'all 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, i.07722}                          

Equally I call up, graphically, these are going to be where your curve "crosses" the axis.

A nice fashion to visualize all three:

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

Note, if you are looking for a way to "filter" and cull simply those solutions that are Real (no imaginary office) you can add together something that keeps only those solutions where the imaginary office is equal to zero.

  • Respond
  • |
  • Flag

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 suit every plot or adding for every single example, 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 event.

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

  • Reply
  • |
  • Flag

Hi,

What almost

x /. Solve[10^3 == -10 && 10 \[Chemical element] Reals, x] // Northward                          

Y'all tin use a like idea to get your plot.

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

And then

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

gives

enter image description here

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

Cheers,

Chiliad.

  • Reply
  • |
  • Flag

Thanks, that sounds interesting. I will wait into information technology

  • Reply
  • |
  • Flag

Some other style to wait at it: for negative real numbers, in that location are several solutions coming from the circuitous roots. For instance, in the case above...

in:= solutions = Solve[10^iii == -ten, 10] // N out:= {{10 -> 1.07722 + one.8658 I}, {10 -> -ii.15443}, {x ->     1.07722 - i.8658 I}}                          

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

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

If y'all don't care to differentiate from among these solutions (though in my opinion, y'all'd be missing out on the all-time office!!) y'all could continue a single, real-valued magnitude:

in:= -1*Flatten@Wedlock@% out:= {-two.15443}                          

This yields a like result as as plotting psurd[] above...

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

piecewise<em>negativereals<em>root</em>plot

  • Reply
  • |
  • Flag
  • Respond
  • |
  • Flag

And thinking some more about Caitlin's observation:

Consider that -1 = Exp[Pi I], then an nth root of -1 is Exp[Pi I / n].

The north nth roots of unity are given by Exp[2 Pi I k / northward] with chiliad from 1 to n. (de Moivres numbers)

Multiplying the nth root of -1 by these gives the due north nth roots of -1 every bit Exp[(2k+1) Pi I / n], again with k from 1 to n.

Since any negative number -Due north (N positive) tin can be written as -one*Northward, we have the nth root as the master root of Due north multiplied by these n roots of -1.

Hither, for example, are nine ninth roots of -i:

In[one]:= rootOfMinusOne[k_, n_] := Exp[(ii grand + 1) Pi I/due north]  In[2]:= roots9 = Table[rootOfMinusOne[k, 9], {thousand, 9}]  Out[2]= {East^((I \[Pi])/3), Due east^((5 I \[Pi])/nine), E^((  7 I \[Pi])/ix), -i, E^(-((7 I \[Pi])/9)), E^(-((5 I \[Pi])/9)), Eastward^(-((   I \[Pi])/iii)), E^(-((I \[Pi])/9)), E^((I \[Pi])/9)}  In[3]:= #^nine & /@ roots9  Out[3]= {-1, -i, -1, -1, -1, -1, -1, -1, -1}  In[iv]:= cPlot[lst_, opts___] :=   ListPlot[{Re[#], Im[#]} & /@ lst, AspectRatio -> one,    AxesLabel -> {"Re", "Im"}, opts]  In[five]:= cplt = cPlot[roots9, PlotLabel -> "The 9 ninth roots of -1"]                          

enter image description here

  • Respond
  • |
  • Flag

Thank you, David. I must give credit where credit is due, to Leonhard Euler!

I was wondering whether someone might suggest a parametric plot for representing real and imaginary components. It is Pi Solar day later all! An alternating, continuous representation that includes the subset you've explored above:

ParametricPlot[{Cos[u], Sin[u]}, {u, 0, 2 Pi},   PlotLabel -> "Cos \[Phi] + \[ImaginaryI] Sin \[Phi]",   AxesLabel -> {"Re", "Im"}]                          

unit<em>circleparametric_plot

  • Reply
  • |
  • Flag

If we have to cite Euler every time we apply his discoveries we will all spend half our time writing citations. ;-)

Happy Pi Day!

enter image description here

  • Reply
  • |
  • Flag

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

In[1]:= ?Surd                                                                                                       Surd[10, n] gives the real-valued north'thursday root of x.  In[2]:= ?CubeRoot                                                                        CubeRoot[x] gives the real-valued cube root of x.                          
  • Reply
  • |
  • Flag

I call up it's on-topic. It still falls brusque of Stefano's want 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 non with Plot.

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

enter image description here

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

enter image description here

  • Reply
  • |
  • Flag

However,

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

enter image description here

  • Answer
  • |
  • Flag

Really Surd works fine in a plot. You used ten every bit the variable in your plotted expression, but Ten in the plot range.

  • Reply
  • |
  • Flag

Thank you, John! That solves a mystery.

  • Reply
  • |
  • Flag

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

  • Reply
  • |
  • Flag

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

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

enter image description here

  • Reply
  • |
  • Flag

Yeah, that is the answer. Cheers!

  • Reply
  • |
  • Flag

The basic mathematical result is that the grand principles of algebra and analysis operate in the complex domain. Oft, yous have to reason through the complex domain to go a real answer. Whatever effort to restrict Mathematica to operate in the real domain will generally touch its ability to break a problem down into subproblems. It is, all the same, often possible to ask for a real upshot:

In[20]:= Solve[x^3 == -10, Element[x, Reals]]  Out[20]= {{10 -> Root[10 + #1^three &, ane]}}  In[21]:= % // N  Out[21]= {{10 -> -two.15443}}                          

The Root object is all the same another style to limited "the real cube root of -10".

  • Respond
  • |
  • Flag

Even so, here you can download the obsolete add-on package which did the task I really demand. Works for version 6

http://library.wolfram.com/infocenter/MathSource/6771/

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 :-(

Attachments:

  • Reply
  • |
  • Flag

I am sure my reply is off topic, but I have puzzled over a similar event 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 information technology will ofttimes throw off an imaginary solution. I have tried to suppress this behavior, because I don't quite know what to exercise with the imaginary role of the solutions.

In the past, some respondents who answered my pleas for assist said that if the imaginary function is small, they ignore information technology! Whoa. In some of my limits of integration, the imaginary function is as large every bit or larger than the existent office. 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.

  • Answer
  • |
  • Flag

Luther, no, probably non an error on your part. Some integrals practise not converge in the limit x -> infinity. For example, solutions for an oscillating system will cycle around a stable state (and take "imaginary" parts). Solutions for an oscillating system, driven at resonant frequency (without proper damping) will diverge! In technology, this tin can accept catastrophic results.

Take an example, or a description of the organisation y'all are trying to model?

  • Reply
  • |
  • Flag

The shortest path between ii truths in the existent domain passes through the circuitous domain. -Jacques Hadamard

Luther, you're probably not making a mistake. This kind of trouble is inherent in mathematics. Integrate uses full general methods to obtain an antiderivative of the given function. Those methods more often than not use complex multivalued functions. When the intended result is real, it often involves canceling imaginary parts of partial results. That, in turn, requires the advisable choice of the values to use for the multivalued functions. At that place is no general style to compute this that is right (for some definition of "correct") in all circumstances. Furthermore, numerical evaluation of an expression that symbolically represents a real number may consequence in a complex number with a small (or ~zero but imprecise) imaginary part because the cancellation isn't perfect using estimate numbers.

  • Reply
  • |
  • Flag

Interesting discussion. My experience in the complex domain was limited to various engineering discussions and formal methods such as Laplace transforms. Imaginary components were a phase shift. Again in the distant past my Fortran integrals using the simple numerical models and were all in the real domain. One time I went into management my brain atrophied. I relied on the smart PhDs working for me to go information technology right!!! LOL.

My have away is that I CAN ignore the imaginary component, even if information technology is very large. On the other hand, I remember some old physics scattering problems in which the imaginary parts represented phase shifts that caused the output moving ridge functions to oscillate with interference patterns...and these were measured and seemed to be real effects.

My integrals are similar to Elliptical integrals, but in that location are boosted terms in the denominator of the integrand function that make an analytical solution impossible. But the numerical integration works very nicely, except that over a certain limited range and size of variable these pesky imaginary components spring up. They may mean something that I but cannot throw away or at least I do so at some run a risk to the validity of my results.

Take a charged ring...so much charge per unit surface area of the ring. If I put a test charge in the vicinity of the first ring, I find a mutual force between the ring and the test charge. If the test charge is on the band axis, the solution is trivial. If the test charge is off-axis, the mutual force requires the solution to an elliptical integral. If I replace the test charge with some other coaxial ring, my result is an elliptical integral. If I extend the band into a disk, the resulting integral is like to an elliptical integral but cannot be solved analytically because now the denominator of the integrand contains additional spatial variables, at to the lowest degree if am correctly recalling my efforts at having Mathematica solve that integral. I switched to numerical integration so long agone I forget how I got there!!!

If I further alter the geometry from disks to spheres using cylindrical symmetry, the integrand is but a little more circuitous and the same limits on finding an belittling solution be. Using spheres I also do not have boosted relative orientation geometries to make thing even more intractable. Now, equally I fool around with the numerical integration making the sizes and distances of the spheres different, these imaginary components to the solutions begin to show up...not always simply under certain circumstances. Fifty-fifty though the problem is a static problem, I am loath to just throw the imaginary components abroad considering information technology is possible that there are some phase furnishings that the integrals are showing me. Information technology could be a scattering trouble if I were looking at the actual dynamics every bit I change the separation distances.

That is my dilemma. What is real and what is not. If I use Plot and utilize the separation distance equally the variable, I get some strange discontinuities at certain distances and sizes. I am trying to track these downward, also. At first I thought it was noise, merely at present I am not and so sure. On the surface, it a straight forward physics problem and I was only looking at information technology to learn how to use Mathematica. Only if the results are not artifacts, that simple problem may not be so simple and direct forward as I had expected. Capiche?

  • Answer
  • |
  • Flag

Do you have examples bachelor? Without that information technology's impossible to tell if you are running into numerical issues or getting legitimate but surprising results.

  • Answer
  • |
  • Flag

My take away is that I CAN ignore the imaginary component, fifty-fifty if it is very big.

Non always, especially if it is large. You can safely ignore imaginary components whose magnitude is small in comparison to your expected/desired numerical precision. On the other manus, a large imaginary component in a event you'd expect to be real is likely a symptom that yous've wandered off onto the wrong branch of a multivalued office. The outcome may be mathematically correct, but in a sense that doesn't use to your physical problem.

  • Respond
  • |
  • Flag

You sound like a lawyer: information technology depends! LOL

Is there a fashion of either eliminating the component or deciding that it can be ignored? Is this even the right question?

In responding to Daniel Lichtblau's requests, I discovered that I accept eliminated this result by my choice of doing NIntegrate and avoiding Integrate. I cannot observe the worksheet that was giving me the imaginary results.

I may have wasted the group's time on this topic, despite what I accept learned, since the issue at present is whether my NIntegrate and NumericQ parametric plots are leading me astray.

  • Reply
  • |
  • Flag

I'm a physicist. I'm used to mathematics needing guidance to properly correspond physical reality. It starts with very simple high school issues. Consider dropping a ball: how long will information technology accept to striking the floor. Well, information technology'due south the solution to an algebra problem:

In[24]:= Solve[ one/2 a t^two == h, t]  Out[24]= {{t -> -((Sqrt[2] Sqrt[h])/Sqrt[a])}, {t -> (    Sqrt[two] Sqrt[h])/Sqrt[a]}}                          

Oops, there are two solutions! However, the ball can't hitting the floor before you drop it, and then we throw out the negative ane. This is completely normal.

Now, for algebra bug at that place are "root isolation" methods that find all solutions rigorously, and Mathematica uses them. And so, you throw out the solutions you don't want and you take the solutions for your problem. However, one time you lot go across algebra, you more often than not can't have confidence that your method, even if it has found a solution, has found every solution to your mathematical problem, nor tin you exist certain that the solution information technology has found is the solution that you want for your physical problem. You're in the realm of "experimental verification".

Comparison results from Integrate and NIntegrate is a expert sort of mathematical experiment, equally they take unlike sorts of problems. You've already encountered Integrate'southward branch cut problem. NIntegrate has the problem that if its sampling of points in the function in question accidentally misses the heady parts, it may yield an entirely bogus result.

Mathematica will not do your thinking for you.

  • Reply
  • |
  • Flag

What you say is true, to a point. Theoretical physicists oft do let the math practise the physics, which is a terrible mistake. The whole high energy physics domain is replete with various predictions built on mathematical symmetries and manipulations. Hence the predictions. It merely took 50 years to observe a Higgs to match i such theory. I personally believe the Higgs is bogus. What good is a theory about mass-energy when y'all cannot predict either in the model?

When I set up a physical problem, I build my agreement of the dynamics into that problem. When Mathematica gives me dorsum results that do not match my expectations, then I have to make a selection based on my understanding of the dynamics or I have to run into if peradventure it is telling me something that is not well understood. Even in taking data, many old timers simply culled the data to collect that which supported their theories or models. Occasionally, they missed a precious stone...like the lambda betoken in low temperature physics. That "pole" was existent.

Enough said. I recollect I am zeroing in on what may be real and what may exist idiosyncratic in my models. I am an experimentalist, and my models meet the needs of setting up measurement procedures and in analyzing the resulting data and determining what I measured and what it means. I accept a lot more than confidence in my data when I have conviction in my mathematics, and Mathematica is so powerful that I am loath to a priori cull the model'due south solution sets without being sure I have not missed my lambda betoken. On the other hand, I am non bang-up on predicting another Higgs-similar phenomenon that can only be stumbled upon after several generations accept passed...and me along with it. That is too much like the old "blind hog finding an acorn."

Thanks for your assist.

  • Reply
  • |
  • Flag

I concord with John. Mathematics is generally wider and deeper than the problems nosotros nowadays to information technology. In physics, it is astonishing to me how many times a model has been stretched, and the unexpected output actually plant in nature, Like Dirac finding the positron on paper.

Simply for many problems, we simply have to be aware of what it's maxim. When Mathematica delivers imaginary parts so small compared to the magnitude of the result that Chop clears them, I generally ascribe them to numerical issues. On the other hand, if you're solving for leg "b" of a right triangle, given the hypotenuse "h" and the other leg "a", it's very possible to ask for Sqrt(h^2-a^2) with a > h. And when Mathematica gives you a complex number for the length of leg "b", it'southward telling you something important.

Kind regards, David

  • Reply
  • |
  • Flag

Hello guys, tin you help me with my problem in this thread?

http://community.wolfram.com/groups/-/chiliad/t/455321

in that word, the formula is just an example of my work using ParametricNDSolveValue, the trouble surfaced when FindRoot have an answer of complex value. is in that location anyway to force FindRoot to present just Existent numbers?

  • Reply
  • |
  • Flag

This word (thread) was locked.

It is getting too many follow-upwards questions that deserve their own discussions.

Moderation Staff

  • Answer
  • |
  • Flag

gravesfolady.blogspot.com

Source: https://community.wolfram.com/groups/-/m/t/458769

0 Response to "Wolfram Mathematica How to Make X Become X Again"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel