Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: FindRoot with a parameter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88883] Re: [mg88858] FindRoot with a parameter
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 20 May 2008 02:27:32 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

FindRoot requires a numeric value for a. You must then use SetDelayed ( := ) instead of Set ( = ) and require only numeric inputs to the function call.

Clear[K];

K[a_?NumericQ] := Module[{x}, x /. FindRoot[a*x == 1/2, {x, 1}]];

Plot[K[a], {a, -1, 1}]

However, for a simple function you don't need numeric techniques and Solve can avoid these issues.

Clear[K];

K[a_] = Module[{x}, x /. Solve[a*x == 1/2, x][[1]]]

1/(2 a)

Plot[K[a], {a, -1, 1}]


Bob Hanlon

---- Aaron Fude <aaronfude at gmail.com> wrote: 
> Hi,
> 
> How does one accomplish something like this:
> 
> K[a_] = FindRoot[a*x == 1/2, {x, 1}]
> 
> My intention is to plot how the zero of a function depends on
> parameters.
> 
> Thanks!
> 
> Aaron
> 



  • Prev by Date: an easy one?
  • Next by Date: Re: RenderBadPicture error while running
  • Previous by thread: Re: FindRoot with a parameter
  • Next by thread: Framed[3, FrameStyle -> None] fails