I often use Gnuplot for fitting data to a function I define myself.
For example, if you have data.txt with input value in the first column, output value in the second column, and if there are any comments they start with a #, you can start Gnuplot, and tell it e.g.
f(x) = C0 + x*(C1 + x*(C2 + x*(C3 + x*(C4 + x*C5))));
fit f(x) "data.txt" using 1:2 via C0,C1,C2,C3,C4,C5
and you can also draw both the sample data and the curve fit using e.g.
plot "data.txt" using 1:2 notitle with points lc "black", f(x) notitle with lines lc "red"
You can print the coefficients using e.g.
print(C0, C1, C2, C3, C4, C5)
but Gnuplot will automatically save a text file called fit.log which contains the fitted variables (C0 through C5, above) under the "Final set of parameters" heading; and all kinds of convergence, error, and correlation matrix information that you may or may not find useful.
If you want the function in a variable name to be used in the plot, you can use sprintf (which has the same syntax the C printf() function has):
fstr = sprintf("f(x) = %f + x*(%f + x*(%f + x*(%f + x*(%f + x*%f))))", C0, C1, C2, C3, C4, C5)
so that
set title fstr ; plot "data.txt" using 1:2 notitle with points lc "black", f(x) notitle with lines lc "red"
will add the function definition as the title of the plot.
I've found this to be very useful when I am still exploring what kind of a function fits my needs most. (In Gnuplot, AB is written A**B, and you can use conditional expressions – (condition ? value-if-true : value-if-false) – in functions. ^|& are binary operators between integers (exclusive-or, or, and, respectively), so 2^5==7 and not 32. == tests for equalty, and != for inequality.)
As an example, when dealing with distances r, I often try to avoid r and 1/r, preferring r2 and 1/r2 instead, because if r is calculated from a vector, odd powers need a "slow" square root, whereas even powers are "cheap" (just need multiplications; and only one division for all even powers of the reciprocal of the distance).
When implementing the function in fixed point format, int(expression) is very useful, because it truncates the expression to an integer. However, the fit variables (C0 through C5, above) must still be treated as reals, as otherwise Gnuplot cannot converge to a solution. (This means, if you try to use int(C0) in f(x), you can expect Gnuplot to not be able to converge to a solution, because small changes in C0 do not have any effect on the result.)