MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FindRoot cannot find obvious solution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47827] Re: [mg47806] FindRoot cannot find obvious solution
  • From: Oleksandr Pavlyk <pavlyk at phys.psu.edu>
  • Date: Wed, 28 Apr 2004 06:56:20 -0400 (EDT)
  • Organization: Penn State University; Department of Physics
  • References: <200404270847.EAA18892@smc.vnet.net>
  • Reply-to: pavlyk at phys.psu.edu
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Mukhtar,

Attributes[NIntegrate]
{HoldAll, Protected}

So s is not evaluated until later.
Your code would look much cleaner if
you kept arguments of your functions
explicitly

h1[x_, y_] = 1 + (y - x)^2;
h2[x_] = 1 + (2/3 - x^2)^2;
b[x_, y_] = h2[x]/(h1[x, y] +
      h2[x]);
s[x_, y_] = FullSimplify[
     x*(1 - x)^2*Evaluate[
       D[b[x, y], y]]];

g[y_] := NIntegrate[s[x, y],
    {x, 0, 1}]

Now, unlike in your code, Plot[g[y],{y,0.2, 0.8}]
does plotting without prolifirating bunch of errors.
Furhermore, it produces correct result for
FindRoot:

FindRoot[g[y], {y, 0.35,
    0.45}, WorkingPrecision ->
    16]

<< Error messages NItegrate::ploss
    suppressed >>

{y -> 0.399370682489405571438\
7173794`16.}

If those messages annoy you, like they do for me,
you can work with the interpolated function

ig = Interpolation[
     Table[{y, g[y]},
      {y, 0.2, 0.8, 0.005}],
     InterpolationOrder -> 5];

Then the result is spit out without errors.

FindRoot[ig[y], {y, 0.35,
    0.45}, WorkingPrecision ->
    16]

{y -> 0.399370682489405632471\
6472443`16.}

So now I've got the question for the group.

It seems to me like a general problem, having
a function f[x], defined via Integral
(or Sum, or Product)

    f[x] = Integrate[ f[x,y],{ y, domain}]

i can plot the function, and see it's zero approximately,
but when fed to FindRoot, I get a bunch of errors.
I do not understand why, but that aside, the only clean
way out is to interpolate f[x] first, and then use FindRoot.

If anybody on the list has a better workaround, please share :).
Your insight would be greatly appreciated.

Regards,
Sasha

Mukhtar Bekkali wrote:
> Here is my code in Mathematica 5:
> 
> h1=1+(y-x)^2;
> h2=1+(2/3-x^2)^2;
> b=h2/(h1+h2);
> f=x(1-x)^2;
> s=f*D[b,y];
> g[y_]:=NIntegrate[s,{x,0,1}];
> FindRoot[g[y]==0,{y,0.35,0.45}]
> 
> The output is
> 
> NIntegrate::inum: Integrand H is not numerical at {x} = {0.5`}.
> FindRoot::cvmit: Failed to converge to the requested accuracy or precision
> within 100 iteration
> 
> and it gives me y->0.45 or the upper boundary. However, when I plot g[y] I
> can see that the solution is somewhere around y=0.4.  Using Solve instead of
> FindRoot does not give me any solutions.
> 
> What am I doing wrong here? Thank you in advance. Mukhtar Bekkali


  • Prev by Date: Re: i don't understand mapping function over a long list
  • Next by Date: Re: bug in IntegerPart ?
  • Previous by thread: Re: FindRoot cannot find obvious solution
  • Next by thread: Re: FindRoot cannot find obvious solution