Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot ± sqrt(x) in one function?

Tags:

gnuplot

Gnuplot uses only positive square root values when sqrt(x) is used. Is there a way to plot both positive and negative values in the same function.

I know of a hack which is to use f(x) = sqrt(x) and g(x) = -sqrt(x) and plot them together and then adjust both functions to use the same line colors but is there a better way?

like image 581
user80551 Avatar asked Oct 09 '13 16:10

user80551


1 Answers

You can plot a parametrized curve:

set parametric
set trange [-10:10]
set samples 1000
plot abs(t), (t > 0 ? 1: -1) * sqrt(abs(t))

to achieve this:

enter image description here

like image 100
Christoph Avatar answered Oct 03 '22 08:10

Christoph