MathGroup Archive 1996

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

Search the Archive

Re: FindRoot question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5505] Re: [mg5424] FindRoot question
  • From: pherron at GSB-Pound.Stanford.EDU (Michael C. Herron)
  • Date: Sat, 14 Dec 1996 19:26:07 -0500
  • Organization: Graduate School Of Business, Stanford University
  • Sender: owner-wri-mathgroup at wolfram.com

In article <58lpm5$7jo at dragonfly.wolfram.com>,
Sherman Reed  <Sherman.Reed at worldnet.att.net> wrote:
>At 05:25 AM 12/7/96 +0000, you wrote:
>>
>>I have a question concerning efficient use of FindRoot.
>>
>>Consider the following code:
>>
>>h=.5
>>
>>k=1
>>
>>f=.2
>>
>>j2[t_,b_]:= -(2*h*k - 4*b*h*k + b*h^2*k + 2*b*h*k^2 - 4*f*t + 4*b*f*t -
>2*b*f*k*t +  b*h*k*t)/(2*(2 - 2*b + b*k)*(-h + t))   
>>
>>j3[t_,b_]:=N[Which [j2[t,b]<0,0,j2[t,b]>1,1,True,j2[t,b]]]
>>
>>j4[z_]:=N[Integrate[b j3[z,b],{b,0,1}]]
>>
>>This works fine.  j2 defines a function, j3 truncates it at 0 and 1,
>>and j4 integrates j3 with respect to one of its arguments.  Nothing
>>complicated here.
>>
>>If I do:
>>
>>Plot [z j4[z]-f,{z,0,1}]
>>
>>I get a nice upward sloping graph that clearly crosses the horizontal
>>axis at about z=.4.  So, z=.4 is approximately a real root.
>>
>>Next, I try:
>>
>>FindRoot [z j4[z]-f,{z,.4}]
>>
>>But (and this is the problem) mathematica just sits there.  I presume
>>it is calculating, but I have been waiting for over 15 minutes and it
>>is still grinding away, this despite the fact that my guess at the
>>root (.4) is alomost correct.  Am I doing something wrong?  Is there
>>an easier way to get mathematica to calculate roots?
>>
>>Thanks.
>>
>>Michael
>>
>>
>I think you did just fine, but not quite in the right format.
>
>I first tried 
>
>FindRoot [z j4[z]-f==0,{z,.4}] and I got an error statement in two or three
>seconds. FindRoot asked for another value for the initial guess, so I gave
>the following:
>

What error message did you get?  Do you know why I would have received
no error message at all?  Another person has suggested that my code
causes mathematica to try to differentiate a Which statement, and this
would cause problems (as explained to me, the way out of this is to
provide two starting values, and this causes FindRoot to use the
secant method rather than Newton's method).  Yet, the lack of an error
message is puzzling, to say the least.

Michael


  • Prev by Date: Q: Function for volume calculation
  • Next by Date: Solution of diff. equation i the form of list?
  • Previous by thread: Re: FindRoot question
  • Next by thread: losing unconvergent roots in FindRoot