Re: Two FindRoot questions

*To*: mathgroup at smc.vnet.net*Subject*: [mg89917] Re: Two FindRoot questions*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Tue, 24 Jun 2008 03:30:40 -0400 (EDT)

On 6/23/08 at 2:48 AM, aaronfude at gmail.com (Aaron Fude) wrote: >These are not FindRoot questions, per se... >Here's a simple example which I want to ask three questions about: >f[k_] := x /. FindRoot[x^2 + k, {x, 0, 10}]; f[-10] Plot[f[k], >{k, -10, 10}] >First, I want the plot to only show where there exists a root. Is >the right solution to make f[] return Null? =46or any continuous function, it is sufficient to show the function is negative at some point and positive at some other point to show a root exists. Rather than plot the function, I would use FindInstant, i.e. In[19]:= FindInstance[x^2 - 10 < 0, x] Out[19]= {{x->0}} In[20]:= FindInstance[x^2 - 10 > 0, x] Out[20]= {{x->Sqrt[11]}} which shows a root to x^2 -10 has to exist between x = 0 and x = Sqrt[11] >How do I make f[] return Null? (Is there a way to "catch" the warnings?) You can make any function return Null by simply defining the arguments for which it should return Null. But this probably isn't something you want to do. Warning and error messages may be "caught" using the built-in function Check. See the documentation for examples of how to use this function. >Finally, I need to solve my equations to 20 digits. How do I do >that? I've read about Accuracy and Precision but it didn't help. Simply setting WorkingPrecision to the number of digits you want will do this when you provide exact numbers for arguments. For example In[21]:= g[k_] := x /. FindRoot[x^2 + k, {x, 0, 10}, WorkingPrecision -> 20] In[22]:= g[-10] Out[22]= 3.1622776601683793320 Note, this will generate an error message if you give k as a machine precision number. This error message can be suppressed using Quiet