MathGroup Archive 1999

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

Search the Archive

RE: nested FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20929] RE: [mg20904] nested FindRoot
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 1 Dec 1999 01:49:59 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Peter Klamser  wrote:
-------------------------

Hello, when I try to use FindRoot on a function that also uses FindRoot
nothing happens. Is because FindRoot has the Attribute HoldAll?

-------------------------

I get it working below.  It probably helps a lot to make sure FindRoot does
not evaluate when it would fail.  Below (f), (g) are only defined when (x1),
(x2) are Real.  If FindRoot did evaluate when (x1),(x2) are symbols it would
fail.

In the definition of (f) I give only one starting value so Newton's method
is used. This works since Mathematica can find the derivative 
D[Exp[t]+t^3-x1, t]

For the definition of (g) I must give two starting points. This causes
FindRoot to use secant method or Brent's method which don't need symbolic
derivatives. Actually I could have used Newton's method if I figured out
what to use for the Jacobian option in FindRoot.

In[1]:=
Off[FindRoot::frmp,FindRoot::frsec];
SetOptions[FindRoot,MaxIterations->100,AccuracyGoal->Infinity];

In[3]:=
f[x1_Real]:=t/.FindRoot[Exp[t]+t^3==x1,{t,0}];
g[x2_Real]:=t/.FindRoot[t^2+f[t]+ArcTan[t]==x2,{t,-300,300}]

In[5]:=
g[3.4]

Out[5]=
-2.44411


Above I get an answer for g[3.4]
Let's verify that it is a valid solution.
At Out[8] we see that (v==f[u]) is True.
Then at Out[9] we see that (u==g[3.4]) is True.
So the solution works.

In[6]:=
u=g[3.4];
v=f[u];

In[8]:=
Exp[v]+v^3==u

Out[8]=
True

In[9]:=
u^2+f[u]+ArcTan[u]==3.4

Out[9]=
True

--------------
Note:
Often times there is an art to getting FindRoot to converge.

--------------------
Regards,
Ted Ersek

For Mathematica tips, tricks see 
http://www.dot.net.au/~elisha/ersek/Tricks.html


  • Prev by Date: fortran dynamic link library
  • Next by Date: Re: Running Mathematica under Linux Red Hat
  • Previous by thread: Re: nested FindRoot
  • Next by thread: RE: (A)/Periodic convex tillings (or near-tillings) of the plane or (3 space)