Hi,

I try to fit some data but do not get the result I want. The problem is, that I have only few data points:

Data file:

# Dosierung pH

0 9.35

1 8.70

2 8.34

3 8.06

4 7.85

5 7.67

What I want, is to create a fitting curve with the corresponding values e.g. the parameters of a cubic fitting.

I tried this with polyfit:

#!/usr/bin/python

from pylab import *

X = load('Dosierung-pH.dat',comments="#")

x = X[:,0]

y = X[:,1]

xlabel(r'$Dosierung H_2P_2O_7~10~[ml]$')

ylabel(r'$pH-Wert$')

# Fitting:

coeffs = polyfit(x,y,4)

besty = polyval(coeffs,x)

xnew = arange(0,5,0.1)

plot (x,y,'bo',x,besty)

show()

Due to the view x-values, the curve is not a curve but a line with kinks.

Using

xnew = arange(0,5,0.1) and

plot (x,y,'bo',xnew,besty)

do not work, because xnew and besty have then not the same length.

The second question is, how can I get the curve values a,b,c,d out ? I would something expect like

y = a*x^3 + b*x^2 + c*x +d

printing the values for a,b,c,d for further using.

Regards

Werner