Group Abstract Group Abstract

Message Boards Message Boards

0
|
20.9K Views
|
12 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Why does Sqrt[] only return positive values rather than +/-?

Posted 10 years ago
Attachments:
POSTED BY: Michael Gmirkin
12 Replies
Posted 10 years ago
POSTED BY: Michael Gmirkin

Here is the sqrt function with only one call to Sqrt:

sqrt[x_] := Module[{sq = Sqrt[x]}, {sq, -sq}]

It's about the same speed as two calls to Sqrt.

But my real point was that if you want different behaviour from a function, go ahead and modify it to suit your needs.

POSTED BY: Eric Johnstone

To add, simply use Contourplot in your endeavours, and use the 'squared' form: y==x^2 rather than 'square-root' form Sqrt[y]==x...

POSTED BY: Sander Huisman
POSTED BY: Sander Huisman
Posted 10 years ago

Hmm, interesting... :)

Though, of course, it's still using two Sqrt functions. But, still another interesting approach to it. ;)

Thx, Eric!

POSTED BY: Michael Gmirkin

You can make your own sqrt function:

sqrt[x_]:={Sqrt[x],-Sqrt[x]}
Plot[sqrt[x],{x,0,4}]

enter image description here

POSTED BY: Eric Johnstone
Posted 10 years ago

So, long and short of it, plot both halves, 'cause there's no other solution? Got it.

Would still prefer there was some way to plot the reflection of the parabola with a single function, rather than 2 half-functions. Ahh well, guess you can't always get what you want, eh? ;)

POSTED BY: Michael Gmirkin

Or even easier, try ContourPlot!

POSTED BY: Sander Huisman

You could use ParametricPlot.

Clear[x, y, t]
x[t_] := t^2;
y[t_] := t;
ParametricPlot[{x[t], y[t]}, {t, -7, 7}]
POSTED BY: Gerard Kopcsay
Posted 10 years ago

Okay, so I thought that maybe wrapping the Sqrt[x] in PlusMinus[] would help.

But, apparently, y=PlusMinus[Sqrt[x]] just makes the top half of the graph ALSO disappear. Grr... This is getting frustrating, now. :o(

So, is it possible to graph the entire function in a single go, or am I going to have to individually graph the upper half and the lower half as separate graphs:

Plot[{y = Sqrt[x], y = -Sqrt[x]}, {x, 0, 50}, PlotRange -> {{0, 50}, {-7, 7}}, 
 Ticks -> {{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50}, {-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6}}]

I don't feel like I should have to go to these lengths to graph something so simple...

What am I doing wrong? Or what is Mathematica doing wrong, and how do we fix it??

POSTED BY: Michael Gmirkin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard