Reputation: 433
This is an extension of my previous question here
Data set in data.dat, codes and figure are, file.dat:
x y
2.53 0.00
0.70 0.99
0.60 2.45
0.49 5.36
0.40 9.31
0.31 18.53
0.22 30.24
0.11 42.23
Code:
f(x) = (x < 0 ? 0 : a*(x/lambda)**(n-1)*exp(-(x/lambda)**n))
n = 0.5
a = 100
lambda = 0.15
fit f(x) 'data.dat' every ::1 via lambda, n, a
set encoding utf8
plot f(x) title sprintf('λ = %.2f, n = %.2f', lambda, n), 'data.dat' every ::1
Figure:
My objective is to get the value of x (In the figure it is at about x = 1) to find the "rise" of the fitted function. So I am wondering if it is possible to take the first order derivative of the fit on the fly and plot it in the same graph in gnuplot? How about second order derivative? TIA.
Upvotes: 2
Views: 1714
Reputation: 15910
It's easy if you don't mind taking the derivative of the fit function analytically yourself:
f(x) = (x < 0 ? 0 : a*(x/lambda)**(n-1)*exp(-(x/lambda)**n))
fp(x) = (x < 0 ? 0 : a*(n-1)*x**(n-2)*exp(-(x/lambda)**n)/lambda**(n-1)*(1 - a*(x/lambda)**n))
plot 'data.dat' title 'data', f(x) title 'fit', fp(x) title 'derivative of fit'
If you want to use a gnuplot function to do the derivative, gnuplot has to do the derivative numerically (e.g. using a multi-point approach as in this example), so it is not quite as nice if you have few data points.
You are almost certainly better off either doing the derivative analytically, or using a non-gnuplot program to do that kind of analysis.
Upvotes: 1