3

I have some code in a Gnuplot file that does curve fitting, currently to a line:

f(x) = m * x + b
fit f(x) "data.txt" using "Days":"Data" via m, b

This works great, but the data looks like it will fit a log curve better. So I tried the following:

f(x) = b + m * log(x)
fit f(x) "data.txt" using "Days":"Data" via m, b

This results in the following error:

line 46: unknown type in real()

What am I doing wrong?

3
  • 2
    Not sure about the internals of how fit works, but if x ever goes negative, log(x) becomes a complex number, which fit may not be prepared to deal with (assuming gnuplots log() implementation even works for negative numbers, instead of returning a "domain error" or other similar condition)... Commented May 19, 2015 at 18:45
  • @twalberg Thanks. x will never go negative for me. Is there a way to constrain it? Commented May 19, 2015 at 19:20
  • 2
    Fitting to non polynomials is usually a bad idea if you can avoid it. If your data looks like a log, then try fitting to a linear function but using preprocessed data, e.g. fit a*x+b "data" using (log($1)):2 via a,b or something like that. Show your data if you want better help figuring out the actual problem here. Commented May 19, 2015 at 19:55

1 Answer 1

2

I just had a similar issue. My data set was small (8 points) on a semi-log plot. When trying to fit, I also received `

unknown type in real()`

I changed my initial parameter estimates and everything works. Hopefully, that helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.