0

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

theozh
  • 22,244
  • 5
  • 28
  • 72
bhaskar
  • 51
  • 5
  • What does "fit command not working" mean? Are you sure you haven`t mixed up the two datasets? One has 3 datapoints the other 8 and you get a polynomial fit through them. Do you just want to limit the green curve to the 3 datapoints? Please clarify. – theozh Mar 15 '21 at 07:59
  • Yes I want to limit the green line to 3 data points – bhaskar Mar 15 '21 at 08:07
  • so, your first dataset shown above is the second in the plot? Please name the datasets in the question to avoid confusion. I understand that `'PmaxPminVEFF1.txt'` has 3 data points and `'PmaxPminVEFF.txt'` has 8 datapoints, correct? – theozh Mar 15 '21 at 08:12
  • yes thats correct – bhaskar Mar 15 '21 at 08:29
  • Does my answer solve your problem? Then please accept the answer indicating that your question is answered. – theozh Mar 18 '21 at 05:23

1 Answers1

0

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

theozh
  • 22,244
  • 5
  • 28
  • 72