From: Szabolcs Horvát on 1 Dec 2007 06:04 Jean-Marc Gulliet wrote: > I bet that the error messages you get are a similar to "FindRoot::srect: > "Value x in search specification {y,x} is not a number or array of numbers." > > Add a condition to your definition of f so it is called only for numeric > arguments. > > In[1]:= Clear[f] > f[x_?NumberQ] := {y /. FindRoot[y^3 + 1 == x, {y, x}][[1]]}[[1]] > FindRoot[f[x] == 0, {x, 3}, AccuracyGoal -> 5] > > Out[3]= {x -> 1.} I'd just like to add a small comment: In these situations it is more correct to use NumericQ instead of NumberQ, otherwise expressions like f[Sqrt[2]] will not evaluate. Sqrt[2] is not an "atomic" number in Mathematica, but a compound expression. However, it does represent a number in the mathematical sense, and N[Sqrt[2]] evaluates to a floating point value. So NumberQ[Sqrt[2]] === False and NumericQ[Sqrt[2]] === True. Of course this does not make a difference if the function f is only used inside FindRoot[]. -- Szabolcs
First
|
Prev
|
Pages: 1 2 Prev: Mathematica 6 and system of matrix and scalar ODEs in NDSolve: Next: Exporting Sound |