Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to fit the log of a set of five data points (NOTE: the second coordinate(y coordinate) in each data point is already a log quantity):

Data={ {.1,.1010}, {.04,0.1192},{.02,0.1555},{.01,0.1777},{.004,0.1789}}  

With a model of the form:

model = a + b*Log[x] + c*(Log[x])^2

My goal is to then plot the fitted model to the data on a log-log plot;

I tried:

Data1 = {{N[Log[10, .1]], .1010}, {N[Log[10, .04]], 
0.1192}, {N[Log[10, .02]], 0.1555}, {N[Log[10, .01]], 
0.1777}, {N[Log[10, .004]], .1789}};

fit = NonLinearModelFit[Data1, model[x], {a, b, c}, x]


fitpoints = 
Table[{x, fit[x]} {x, 0, .1, .004}]

llf = ListLogLogPlot[fitpoints, Joined -> True]

Show[llf, Log[10,data]]

Obviously I didn’t get far since the NonLinearFitModel gives complex numbers. I looked at the suggested answers but could not find anything relevant as far as the complex number issue. I would much appreciate any help as to solving this problem i.e.; show the data and it’s fitted model on a Log-Log Plot.


share|improve this question

closed as off-topic by Sjoerd C. de Vries, Michael E2, Yves Klett, Artes, rm -rf Aug 13 '13 at 14:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sjoerd C. de Vries, Michael E2, Yves Klett, Artes, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

"Log base 10 of a decimal number is a complex number"; I think you mean the log of a negative number is complex. Log10 of 0.5, for example, is a very real -0.301... –  bobthechemist Aug 12 '13 at 12:12
If you change the data you need to change the model accordingly. The complex numbers come from evaluating the log of a negative number. –  b.gatessucks Aug 12 '13 at 12:12
Yes log of a negative number is complex. –  ressci Aug 12 '13 at 12:23
Please, correct the inconsistent naming convention used in your code. –  Sektor Aug 12 '13 at 12:25
My apologies - I mean't to say that the NonLinearModelFit gave me complex numbers which could not be handled by a ListLogLogPlot (of course). My apologies, I had not entered that correctly.. –  ressci Aug 12 '13 at 12:27

1 Answer 1

This will probably be closed since it's a modeling mistake, but just to help out the OP:

data = {{.1, .1010}, {.04, 0.1192}, {.02, 0.1555}, {.01, 
   0.1777}, {.004, 0.1789}}
nlm = NonlinearModelFit[
  a + b Log10[x] + c Log10[x]^2,
  {a, b, c},
Plot[nlm[x], {x, 0, 0.1}, Epilog -> {Red, Point@data}]
Plot[nlm[10^x], {x, -3, 0}, 
 Epilog -> {Red, 
   Point@Transpose[{Log10[data[[All, 1]]], data[[All, 2]]}]}]

The 2nd plot gives the log log plot that was requested:

Mathematica graphics

and the 1st is the original function (which I find easier to understand, but that's just me perhaps):

Mathematica graphics

share|improve this answer
Thanks very much for your answer, especially given my mistakes on posing the question. The second plot looks more realistic in terms of what I expect the curve to look like. –  ressci Aug 12 '13 at 12:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.