Re: Using FindRoot on an equation involving Log terms
- To: mathgroup at smc.vnet.net
- Subject: [mg115727] Re: Using FindRoot on an equation involving Log terms
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Wed, 19 Jan 2011 05:27:45 -0500 (EST)
The function's derivative at the root is rather large, so an accurate
solution requires a bit of work.
It needn't be this verbose, but here's an approach that works well when
the plot is well-behaved:
Clear[expr]
expr[x_] =
110.52499999999998 + (300. - 135.52499999999998/(1 - x)) (1 - x) -
300. x - 135.52499999999998 Log[1 - x] +
135.52499999999998 Log[x];
p0 = Plot[expr@x, {x, 0, 1}];
pt1 = First@Cases[p0, Line[pts_List] :> pts, Infinity];
p1 = ListPlot[pt1, PlotRange -> All];
pt2 = pt1 /. {x_, y_} -> {x, Abs@y};
p2 = ListPlot@pt2;
sorted = SortBy[pt2, Last];
x0 = sorted[[1, 1]]
root = x /. FindRoot[expr@x, {x, x0}]
0.849313
0.849823
expr /@ {x0, root}
{-0.235046, -2.84217*10^-14}
expr'[root]
461.91
Notice the large derivative and how far off (vertically) is the plot's
closest point to the root.
highLow = {root, #} & /@ pt1[[{1, -1}, -1]];
Show[p0, p1, p2, Graphics@{Thick, Red, Line@highLow}]
Bobby
On Tue, 18 Jan 2011 04:51:50 -0600, Andrew DeYoung
<adeyoung at andrew.cmu.edu> wrote:
> Hi,
>
> I am trying to find the root of a certain expression in Mathematica
> version 7:
>
> expr = 110.52499999999998 + (300. - 135.52499999999998/(1 - x)) (1 -
> x) - 300. x - 135.52499999999998 Log[1 - x] + 135.52499999999998
> Log[x]
>
> It appears to plot fine, for example using Plot[expr, {x, 0, 1}]. The
> plot shows that there should be a root at about x=0.85. However, when
> I try to find this root, using for example the following:
>
> FindRoot[expr, {x, 0.5}]
>
> I get an error message:
>
> "FindRoot::lstol: The line search decreased the step size to within
> tolerance specified by AccuracyGoal and PrecisionGoal but was unable
> to find a sufficient decrease in the merit function. You may need
> more than MachinePrecision digits of working precision to meet these
> tolerances."
>
> and it prints a seemingly incorrect (according to the qualitative form
> of the plot) result: {x -> 0.344678}. Only if I use for example
>
> FindRoot[expr, {x, 0.7}]
>
> do I get the seemingly "correct" root: {x -> 0.849823}.
>
> Can you help me see why the FindRoot is getting stuck at {x ->
> 0.344678} when I use starting values far away from 0.7 or 0.8? I will
> ultimately want to find the roots of many similar functions, which may
> have more than one "actual" root, so it would be helpful if I could
> see why FindRoot[expr, {x, 0.5}] does not give {x -> 0.849823}. (also
> when I tried NSolve[expr==0,x], Mathematica will not solve it.)
>
> Thank you,
>
> Andrew DeYoung
> Carnegie Mellon University
>
--
DrMajorBob at yahoo.com