Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: FindMaximum query

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85560] Re: [mg85530] FindMaximum query
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Wed, 13 Feb 2008 07:44:08 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Restrict fun to numeric arguments

Clear[fun];

fun[x_?NumericQ] := Module[{y, sol},
  sol = FindRoot[Sqrt[y] == Abs[x], {y, 0, 0.001}];
  (*AppendTo[list,sol];*)
  -y /. sol[[1]]]

FindMaximum[fun[x], {x, 1, 1.001}]

{0., {x -> -1.7585932710058097*^-16}}


Bob Hanlon

---- "E. Neely Atkinson" <eatkinso at mdanderson.org> wrote: 
> Consider the following function:
> 
> fun[x_] :=
>  Module[
>   {y, sol},
>   sol = FindRoot[Sqrt[y] == Abs[x], {y, 0, 0.001}];
>   (* AppendTo[list, sol]; *)
>   -y /. sol[[1]]
>   ]
> 
> Then Plot[fun[x], {x, -2, 2}] works fine, but
> 
> FindMaximum[fun[x], {x, 1, 1.001}]
> 
> fails. If I uncomment the debug line in fun and execute 
> 
> list = {};
> FindMaximum[fun[x], {x, 1, 1.001}]
> 
> Then list contains
> 
> {FindRoot[Sqrt[y$21471] == Abs[x], {y$21471, 0, 0.001}]}
> 
> 
> So, FindRoot fails because x is passed through unevaluated, I think.
> I would appreciate any advice on how to get FindMaximum (or NMaximize)
> to work in this case.
> 
> Mathematic 6.0.1.0 x86 32 bit
> Mac OS X 10.4.11
> 
> Thanks very much,
> 
> E. Neely Atkinson
> Department of Biostatistics
> M. D. Anderson Cancer Center
> 
> neely at pdq.net
> 



  • Prev by Date: Re: Re: Reduce in Ver 6
  • Next by Date: Re: Local variable in ToExpression?
  • Previous by thread: Re: FindMaximum query
  • Next by thread: Mathematica and Google Desktop