2
$\begingroup$

I have the following defined:

lvf1 = Table[{i, 1/(10 - i)}, {i, -100, 100}];

If I just run this, it gives me a "Power: Infinite expression 1/0 encountered." error, so I added this to remove that point from the dataset:

lvf1 = Delete[lvf1, 111];

It looks like this:

ListPlot[lvf1]

enter image description here

Now, when I run this:

nlm = NonlinearModelFit[lvf1, a/(b - x) + c, {a, b, c}, x];

I get all kinds of errors:

enter image description here

Why!? I've used the NonlinearModelFit function like this elsewhere, and it typically works. I can't seem to get it to work with any reciprocal/inverse type function. Please help!

$\endgroup$

2 Answers 2

3
$\begingroup$

Provide a non-integral initial point:

NonlinearModelFit[lvf1, a/(b - x) + c, {a, {b, π^2}, c}, x]
$\endgroup$
1
  • $\begingroup$ A non-integral initial point for b does remove the error messages but the initial value of $\pi$ doesn't result in an appropriate fit. If {a, {b, 9.1}, c} is used, then an appropriate fit is found. $\endgroup$
    – JimB
    Nov 20, 2018 at 1:08
0
$\begingroup$

You don't need initial points when using Method->"NMinimize"

nlm = NonlinearModelFit[lvf1, a/(b - x) + c, {a, b, c}, x,Method -> "NMinimize"];
Normal[nlm] (*  -8.88269*10^-9 + 1./(10. - x)  as expected*)

Show[{Plot[Normal[nlm], {x, -100, 100}, PlotStyle -> Thickness[.02]],ListPlot[lvf1, PlotStyle -> Red]}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Do you mean that using Method -> "NMinimize" starts out with either better automatic initial points or that using that method is less sensitive in this case to the automatic initial points (which I thought was 1 for all parameters)? It's still an iterative method so there must be initial points. $\endgroup$
    – JimB
    Nov 20, 2018 at 14:26
  • $\begingroup$ @ JimB I don't know which initial points NMinimize uses, often the method is more robust than the default methods. $\endgroup$ Nov 20, 2018 at 14:47
  • $\begingroup$ Thanks. I see now. That method is more robust which means that it is much less often that one needs to supply customized initial values. $\endgroup$
    – JimB
    Nov 20, 2018 at 15:13

Your Answer

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

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