0
$\begingroup$

I have a set of data which I give here

data = {{0.294320000000000026`7., 23.8843734496254604949`7.}, {0.6795160000000000089`7., 23.8843611997525542279`7.}, 
   {1.0502000000000000224`7., 23.8843489498796444082`7.}, {1.4071700000000000319`7., 23.8843367000067381412`7.}, {1.7511799999999999589`7., 23.8843244501338318742`7.}, 
   {2.0829300000000001702`7., 23.8843122002609220544`7.}, {2.4030499999999999083`7., 23.8842999503880157874`7.}, {2.7121499999999998387`7., 23.8842877005151095204`7.}, 
   {3.0107800000000000118`7., 23.8842754506421997007`7.}, {3.2994699999999999029`7., 23.8842632007692934337`7.}, {3.5787100000000000577`7., 23.884250950896383614`7.}, 
   {3.8489599999999999369`7., 23.884238701023477347`7.}, {4.1106400000000000716`7., 23.88422645115057108`7.}, {4.3641500000000004178`7., 23.8842142012776612603`7.}, 
   {4.6098699999999999122`7., 23.8842019514047549933`7.}, {4.8481500000000004036`7., 23.8841897015318487263`7.}, {6.8864700000000000912`7., 23.8840672028027718454`7.}, 
   {8.4512300000000006861`7., 23.8839447040736949646`7.}, {9.6903000000000005798`7., 23.8838222053446180837`7.}, {10.6958000000000001961`7., 23.8836997066155447556`7.}, 
   {11.5281000000000002359`7., 23.8835772078864678747`7.}, {15.6127000000000002444`7., 23.8823522205957097242`7.}, 
   {17.1147999999999989029`7., 23.8811272333049551264`7.}, {17.9021000000000007901`7., 23.8799022460141969759`7.}, 
   {18.3740999999999985448`7., 23.8786772587234423781`7.}, {18.6981000000000001648`7., 23.8774522714326842276`7.}, 
   {18.9327000000000005286`7., 23.8762272841419260772`7.}, {19.117100000000000648`7., 23.8750022968511714794`7.}, 
   {19.8338999999999998636`7., 23.8627524239436006326`7.}, {20.0574000000000012278`7., 23.8505025510360333385`7.}, 
   {20.1506000000000007333`7., 23.8382526781284624917`7.}, {20.2182999999999992724`7., 23.8260028052208951976`7.}, 
   {20.2663000000000010914`7., 23.8137529323133279036`7.}, {20.3024999999999984368`7., 23.8015030594057606095`7.}, 
   {20.3335000000000007958`7., 23.7892531864981897627`7.}, {20.359200000000001296`7., 23.7770033135906224686`7.}, 
   {20.3817999999999983629`7., 23.7647534406830516218`7.}, {20.5414999999999992042`7., 23.6422547116073644702`7.}, 
   {20.6695999999999990848`7., 23.5197559825316808713`7.}, {20.7867999999999994998`7., 23.3972572534559937196`7.}, 
   {20.9030999999999984595`7., 23.274758524380306568`7.}, {22.0936999999999983402`7., 22.0497712336234528152`7.}, {23.4103999999999992099`7., 20.824783942866591957`7.}, 
   {24.8888999999999995794`7., 19.5997966521097346515`7.}, {26.5626999999999995339`7., 18.3748093613528737933`7.}, 
   {28.4742999999999994998`7., 17.1498220705960164878`7.}, {30.6789999999999984936`7., 15.9248347798391591823`7.}, 
   {33.2490999999999985448`7., 14.6998474890823001004`7.}, {36.2854999999999989768`7., 13.474860198325442795`7.}, 
   {39.9273000000000024556`7., 12.2498729075685837131`7.}, {44.376300000000000523`7., 11.0248856168117264076`7.}, {49.935099999999998488`7., 9.7998983260548673258`7.}, 
   {57.0788999999999973056`7., 8.5749110352980082439`7.}, {66.5995999999999952479`7., 7.3499237445411500502`7.}, {79.9188999999999936108`7., 6.1249364537842918566`7.}, 
   {99.8800999999999987722`7., 4.8999491630274336629`7.}, {133.0889999999999986358`7., 3.6749618722705750251`7.}, 
   {199.2379999999999995453`7., 2.4499745815137168314`7.}, {393.9680000000000177351`7., 1.2249872907568584157`7.}}

And I am trying to fit to a model. In order to do so, I have the following

fitfunction[x_] := a + b*Log[c*x + d*x^2]
sltnmodel = FindFit[data, fitfunction[x], {a, b, c, d, e}, x, MaxIterations -> Infinity]
Show[ListPlot[data, PlotRange -> {{-170, 500}, {-0.1, 25}}, PlotMarkers -> Style["\[FilledCircle]", 11, Red], BaseStyle -> {13, FontFamily -> "Times New Roman"}, 
   AxesLabel -> {"\!\(\*SuperscriptBox[\(g\), \(2\)]\)", "\!\(\*SubscriptBox[\(M\), \(B\)]\)/\!\(\*SubscriptBox[\(f\), \(\[Pi]\)]\)"}, Joined -> False], 
  Plot[fitfunction[x] /. sltnmodel, {x, 0, 600}, PlotRange -> {{-170, 500}, {-0.1, 25}}, PlotStyle -> {Dashed, Black}]]

The result of the plot is shown below.

The plot

So the fitting needs some more work.

The problem is that if add something to the existing Log fit it gives the following error message.

enter image description here

I tried to use the answer that was given here, but it does not fix the problem.

Any ideas?

$\endgroup$
  • $\begingroup$ what do you mean: if add something? $\endgroup$ – Fraccalo Jan 23 at 9:23
  • 1
    $\begingroup$ Interesting that both FindFit and NonlinearModelFit give the same (bad?) fitted parameters. $\endgroup$ – Lotus Jan 23 at 9:26
  • $\begingroup$ @Fraccalo I mean that you can take the piece that is written in the code above and try to add f x^2 for example or any other function $\endgroup$ – DiSp0sablE_H3r0 Jan 23 at 9:29
  • 1
    $\begingroup$ @A_user_with_NoName try adding Abs[] within the Log argument. I think the problem arises from mathematica trying to compute negative logs $\endgroup$ – Fraccalo Jan 23 at 9:32
  • 1
    $\begingroup$ Using Fraccalo's comment above, a + bLog[Abs[cx + d*x^2 e x^4]] makes it better. It seems that you should split the data into two sets. I will elaborate in an answer. $\endgroup$ – Lotus Jan 23 at 9:40
2
$\begingroup$

As I mentioned in my comment, it looks like the problem is the Log trying to evaluate when the argument is negative. Adding Abs in the argument might help.

Also, the model itself doesn't seem to match the data: are you sure that data should follow that function?

It looks to me that Exp[-x^(1/2)] fits the data better:

fitfunction[x_] := b*Exp[-c*x^(1/2) + d]
sltnmodel = 
 FindFit[data[[27 ;;]], 
  fitfunction[x], {{a, 0}, {b, 1}, {c, .01}, {d, 0}, {e, 1}}, x, 
  MaxIterations -> Infinity]

enter image description here

Please note that you can add an additional vertical offset "a", remove the horizontal offset "d" etc (if it makes sense in your model).

Also, I'm neglecting the first 26 data points when fitting as they seem to arise from a different distribution: probably your model should take this into account as well, but without any prior knowledge of what we are looking at, it's hard to tell.

Anyhoo, I hope that this will give you enough material to play with, and to understand your data better.

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Exactly what I meant by splitting the data set. Great ! $\endgroup$ – Lotus Jan 23 at 9:46
  • $\begingroup$ Thanks for the detailed answer. I actually had in mind to split the FitFunction in two sets in the end and match, but I started facing the problem I mentioned and for my purposes, it is the points after the first 26 that are more interesting. $\endgroup$ – DiSp0sablE_H3r0 Jan 23 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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