gnuplot fitting extends the points assigned. how to solve this error?

56 Views Asked by At

I have 2 sets of data file

#veff   S   Pmax    S   Pmin
0.10    103 0.2135  152 -0.0505
0.11    104 0.2162  152 -0.0592
0.12    105 0.2177  152 -0.0669

and

#veff   S   Pmax    S   Pmin
0.13    106 0.2177  152 -0.0729
0.14    105 0.2162  152 -0.0778
0.15    105 0.2127  152 -0.0819
0.16    105 0.2078  152 -0.0858
0.17    105 0.2018  153 -0.0879
0.18    104 0.1959  153 -0.0889
0.19    104 0.1907  153 -0.0898
0.20    103 0.1860  153 -0.0921

while I try to fit the fit goes beyond the points with the code

set terminal wxt
#set term postscript eps color enhanced
#set output "1.eps"
set xlabel "Pmax"
set ylabel "Pmin"
[![enter image description here][1]][1]
set title "Pmax vs Pmin"
unset key

FIT_LIMIT = 1e-6
f1(x)=a1*x*x+b1*x+c1
f2(x)=a2*x*x+b2*x+c2

fit [x=0.185:0.218] f1(x)  "PmaxPminVEFF.txt" u 3:5 via a1,b1,c1 
fit [x=0.212:0.218] f2(x) "PmaxPminVEFF1.txt" u 3:5 via a2,b2,c2

plot 'PmaxPminVEFF.txt' using 3:5 with p pt 7,f1(x) lc rgb "red",\
    'PmaxPminVEFF1.txt' using 3:5 with p pt 8, f2(x) lc rgb "green"

the fitting line goes beyond the points. Help me out here to fix the fittings up to the point only. Fit command is also not working.

enter image description here

1

There are 1 best solutions below

0
On

Check the following:

Code:

### Limit fitted plot to data
reset session

$Data1 <<EOD
#veff   S   Pmax    S   Pmin
0.13    106 0.2177  152 -0.0729
0.14    105 0.2162  152 -0.0778
0.15    105 0.2127  152 -0.0819
0.16    105 0.2078  152 -0.0858
0.17    105 0.2018  153 -0.0879
0.18    104 0.1959  153 -0.0889
0.19    104 0.1907  153 -0.0898
0.20    103 0.1860  153 -0.0921
EOD

$Data2 <<EOD
#veff   S   Pmax    S   Pmin
0.10    103 0.2135  152 -0.0505
0.11    104 0.2162  152 -0.0592
0.12    105 0.2177  152 -0.0669
EOD

set xlabel "Pmax"
set ylabel "Pmin"
set title "Pmax vs Pmin"
unset key

FIT_LIMIT = 1e-6
f1(x) = a1*x**2 + b1*x + c1
f2(x) = a2*x**2 + b2*x + c2

fit [x=0.185:0.218] f1(x) $Data1 u 3:5 via a1,b1,c1 
fit [x=0.212:0.218] f2(x) $Data2 u 3:5 via a2,b2,c2

plot $Data1 using 3:5 with p pt 7, \
     [x=0.185:0.218] f1(x) lc rgb "red",\
     $Data2 using 3:5 with p pt 8, \
     [x=0.212:0.218] f2(x) lc rgb "green"
### end of code

Result:

enter image description here