1
$\begingroup$

I am trying to fit my experimental data to a very complicated equation which contains digamma function. I tried to learn from various discussions about fitting but I could not quite figure out how to deal with it. Posted are my experimental data and function I want to fit with. I am a new Mathematica user. Can anyone help me?

data= {{37.6, 0}, {32.1, 1}, {25.6, 2}, {20.1, 3}, {15.2, 4}, {11.1,4.5}, {8.4, 5}, {5.6, 5.5}, {2.1, 6.5}, {0, 7.}}

Function I want to fit is rather bulky defined as follows,

eq=(0.564 + a) (Log[x/41] + PolyGamma[0.5 + p1] + 1.96351) + (0.564 - a)(Log[x/41] + PolyGamma[0.5 + p2] + 1.96351) + 0.44 (Log[x/41] + PolyGamma[0.5 + p1] + 1.96351) (Log[x/41] + PolyGamma[0.5 + p2] + 1.96351)== 0

a= (-3.11*^11 + 0.52 (1.97*^11 + 
  1.82*^15 y (1 - b)))/(2.25*^24 + (1.97*^11 + 1.82*^15 y (1 - b))^2)^0.5;
p1= (1/x)3.81*10^-12 (1.51*10^12 + (2.25*10^24 + (1.97*10^11 + 1.82*10^15 y (1 - b))^2)^0.5 + 1.82*10^15 y (1 + b));

P2=(1/x)3.81*10^-12 (1.51*10^12 - (2.25*10^24 + (1.97*10^11 + 1.82*10^15 y (1 - b))^2)^0.5 + 1.82*10^15 y (1 + b));

The fitting parameter is only 'b' and plot should be y vs x.

I tried this:

NonLinearModelFit[data,(0.564 + a) (Log[x/41] + PolyGamma[0.5 + p1] + 1.96351) + (0.564 - a)(Log[x/41] + PolyGamma[0.5 + p2] + 1.96351) + 0.44 (Log[x/41] + PolyGamma[0.5 + p1] + 1.96351) (Log[x/41] + PolyGamma[0.5 + p2] + 1.96351), {b},{x,y}]

Unfortunately, it gives nothing.

$\endgroup$
  • 2
    $\begingroup$ I think you have a couple of typos: you define P2, but then later use p2 (lower case), and NonlinearModelFit has no capital "L". $\endgroup$ – aardvark2012 Jul 1 '17 at 11:45
1
$\begingroup$

You have a data point {0, y} even though the formula contains Log[x/41]. I exclude that data point. Also you have used P2 and p2 interchangeably. I remove the == from eq because it should only be there when you want something to be exact equal (except for rounding error).

eq = (0.564 + a) (Log[x/41] + PolyGamma[0.5 + p1] + 1.96351) +
     (0.564 - a) (Log[x/41] + PolyGamma[0.5 + p2] + 1.96351) +
            0.44 (Log[x/41] + PolyGamma[0.5 + p1] + 1.96351)
                 (Log[x/41] + PolyGamma[0.5 + p2] + 1.96351);

a = (-3.11*^11 + 0.52 (1.97*^11 + 1.82*^15 y (1 - b)))/
     (2.25*^24 + (1.97*^11 + 1.82*^15 y (1 - b))^2)^0.5;
p1 = (1/x) 3.81*10^-12 (1.51*10^12 + (2.25*10^24 + (1.97*10^11 +
           1.82*10^15 y (1 - b))^2)^0.5 + 1.82*10^15 y (1 + b));
p2 = (1/x) 3.81*10^-12 (1.51*10^12 - (2.25*10^24 + (1.97*10^11 +
           1.82*10^15 y (1 - b))^2)^0.5 + 1.82*10^15 y (1 + b));

err[b_?NumericQ] = Total[Map[eq^2 /. {x -> #[[1]], y -> #[[2]]} &, data[[;; -2]]]];

NonlinearModelFit only works if you can solve the equation for y. I don't think it's possible so the function err computes sum of eq squares instead, which can be minimized with respect to b (you want eq to be close to 0). Looking at

ListPlot[Table[{b, err[b]}, {b, -2, 2, 1/10}]]

enter image description here

The minimum seems to be about b==0, so we get:

FindMinimum[err[b], {b, 0.00001, 0}]

{428.80412, {b -> -0.000056068596}}

$\endgroup$

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.