Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find the slope use gnuplot ?

1,783 views
Skip to first unread message

dagao

unread,
Nov 17, 2001, 5:09:29 PM11/17/01
to
hi,there,
Anyone know how to find out the slope of a curve in gnuplot?
Thanks!
Da Gao


Hans-Bernhard Broeker

unread,
Nov 19, 2001, 6:58:04 AM11/19/01
to
dagao <da...@mtu.edu> wrote:
> hi,there,
> Anyone know how to find out the slope of a curve in gnuplot?

I assume you mean the derivative (a curve doesn't usually have a slope
--- only a straight line has). gnuplot offers no direct method to access
the derivative. For functions, you can do a numeric approximation like this:

epsilon = 0.001
derivative_of_f = (f(x*(1+epsilon) - f(x*(1-epsilon))) / (2*epsilon*x)

This won't work close to x=0.

For datafiles, you'll have to use methods outside gnuplot. The following
'awk' script does nicely, for columns 1 and 2 as x and y:

#! /bin/awk -f
BEGIN { firstline = 1 }

$0 !~ /^#/ { if (firstline == 1) {
old_x = $1
old_y = $2
firstline = 0
} else {
print (old_x + $1)/2.0, "\t", (old_y - $2)/(old_x - $1), "\t"
old_x = $1
old_y = $2
}
}

You can run it like this, on sufficiently Unix-oid platforms:

plot '< diff.awk yourdatafile' using 1:2


--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

dagao

unread,
Nov 19, 2001, 10:50:21 AM11/19/01
to
Can you check the plot command?It does not work.Thanks!
"Hans-Bernhard Broeker" <bro...@physik.rwth-aachen.de> wrote in message
news:9tas4c$jha$1...@nets3.rz.RWTH-Aachen.DE...
0 new messages