tags:

views:

258

answers:

2

Hi,

Gnuplot, a great package ... I'm in love with it. But we can have our tiffs as well, as any couple :-) This time, I wanted to simply plot the roots of an equation: say a quadratic to keep things simple. However, I only want two nice round dots appearing on the x-axis representing the point where the quadratic crosses the x-axis or y=0 axis. In other words the roots (when they are real that is). I don't want to do this with datafile ... I want gnuplot to calculate the roots and plot them.

First off, my attempts: single points aren't really what gnuplot would have you plot, it likes a good wide range of values. Preferably filling up the whole width of your canvas.

It's possible to locate a rectangle at a certain coordinate on your plot, but I wanted a round point. Currently I'm chasing up how to do a tiny filled polygon at that point. I have tried the "samples" option bu it doesn't seem useful.

Also though about defining a dirac-delta function so that only one point would be highlighted (though two would be needed).

ANy suggestions welcome, thanks.

A: 

Not sure if this really helps, but if you can define a custom function to calculate the roots, gnuplot will display it.

sapporo
A: 

there is a way, but it takes just a little bit of fiddling

narrowness=1
set yrange [0:10]
set xrange [-10:10]
poly(x)=(x**2+3*x-2)
roots(x) =floor(narrowness*poly(x))?1/0:0
plot roots(x) w points pt 7 

depending on the function and the range you will need to set the width differently. if you see too many circles increase the narrowness, if you see too few (aka. none) decrease the narrowness

Cheers!

/B2S

oh, and PS. to increase accuracy set samples to some higher value

And Alternatively if you happen to already know the roots, say r1(2,0) and r2(-1,0) then you can plot them using

plot '-' with points pt 7
2 0
-1 0
e
Born2Smile