MathGroup Archive 2008

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

Search the Archive

Re: Two FindRoot questions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89904] Re: Two FindRoot questions
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 24 Jun 2008 03:28:12 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g3nha1$f9$1@smc.vnet.net>

Aaron Fude wrote:

> These are not FindRoot questions, per se...

You will find below a possible approach to your problem(s) that does not 
use FindRoot and only plots the points for which the function has a real 
root.

> 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?
> How do I make f[] return Null? (Is there a way to "catch" the
> warnings?)
> 
> 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.

f[k_] := First[Cases[x /. Solve[x^2 + k == 0, x],
          (x_)?NonNegative /; x <= 10] /. {} -> {None}]

pts = Table[{k, f[k]}, {k, -10, 10}];

ListPlot[pts, Filling -> Axis]

N[#1, 20] & /@ pts // DeleteCases[#1, {_, None}] &

Cases[pts, {x_, (y_)?NumericQ} :> (N[#1, 20] & ) /@ {x, y}]

{{-10.0000000000000000000,
   3.1622776601683793320}, {-9.0000000000000000000,
   3.0000000000000000000}, {-8.0000000000000000000,
   2.8284271247461900976}, {-7.0000000000000000000,
   2.6457513110645905905}, {-6.0000000000000000000,
   2.4494897427831780982}, {-5.0000000000000000000,
   2.2360679774997896964}, {-4.0000000000000000000,
   2.0000000000000000000}, {-3.0000000000000000000,
   1.7320508075688772935}, {-2.0000000000000000000,
   1.4142135623730950488}, {-1.00000000000000000000,
   1.00000000000000000000}, {0, 0}}

Regards,
-- Jean-Marc


  • Prev by Date: Mathematica upgrade to 6.0.3
  • Next by Date: Re: FindROot and substitutions
  • Previous by thread: Re: Two FindRoot questions
  • Next by thread: strange behaviour of background color in Panel[]