JunChai
JunChai

Reputation: 13

How to obtain point data from a fitting curve?

I plotted curves by fitting some existing points using gnuplot.

code as followings:

f1(x)=a1/(x**b1)+c1
fit f1(x) "41a091_input.txt" u 1:2 via a1,b1,c1
plot f1(x) with line lt 1 lw 4 lc rgb "blue" notitle, \
    '41a091_input.txt' using 1:2:3 with yerrorbars lw 2.2 lc rgb "blue" title "∑41a(091)"

Data as followings:

21.8124 1.11693 0.00545168
30.8669 1.07328 0.00485237 
44.6701 1.04708 0.00411839
53.6699 1.03787 0.00301346
75.9751 1.02555 0.00304312

My question is:

How to get data from any point on this curve? Like when x=50?

Upvotes: 1

Views: 87

Answers (1)

theozh
theozh

Reputation: 25714

well, you have your fitting function f1(x) and the parameters a1,b1,c1 have been fitted. So, in order to get the value at x=50, simply type print f1(50). Or if you want to plot it:

### start code
reset session

$Data <<EOD
21.8124 1.11693 0.00545168
30.8669 1.07328 0.00485237 
44.6701 1.04708 0.00411839
53.6699 1.03787 0.00301346
75.9751 1.02555 0.00304312
EOD

f1(x)=a1/(x**b1)+c1
fit f1(x) $Data u 1:2 via a1,b1,c1
print sprintf("a1: %g, b1: %g, c1: %g", a1,b1,c1)

XValue = 50
set label 1 at XValue,f1(XValue)+0.01 sprintf("f1(%g): %g",XValue,f1(XValue)) 
set arrow 1 from XValue,graph 0 to XValue,graph 1 nohead ls 0

plot f1(x) with line lt 1 lw 4 lc rgb "blue" notitle,\
 $Data using 1:2:3 with yerrorbars lw 2.2 lc rgb "blue" title "∑41a(091)",\
 [XValue:XValue] f1(XValue) w p lt 6 lc rgb "red" ps 2
### end of code

which results in something like: enter image description here

Upvotes: 1

Related Questions