1
votes

Is there a way to contraint the values that fitting parameters can take with gnuplot?

f(x) = A/(x**2) + B/(x**4)
A = 1
B = 0.01
fit f(x) 'data.dat' u 1:2 via A,B

I know that B < 0 doesn't make any sense. Is there a way to impose B > 0?

2

2 Answers

2
votes

Since gnuplot supports non-linear fitting you can use B**2 (or sqrt(B**2)) in your function to constrain your variable to be positive.

0
votes

You could change your function to something like this:

minB = 0.001
f(x) = A*x**-2 + (B<minB:minB:B)*x**-4

But i'm not sure how the NLLS alogrithm reacts to this. Beware.

Or you might think about something like this:

f(x) = A*x**-2 + 10**B*x**-4

Probably this will react much smoother and be closer to an actual physical model of your data.