Re: Result from FindRoot
- To: mathgroup@smc.vnet.net
- Subject: [mg10956] Re: Result from FindRoot
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Sat, 14 Feb 1998 00:53:27 -0500
- References: <6bumvr$l98@smc.vnet.net>
Torbjörn Randahl wrote:
> How do I use the result from FindRoot in a Plot?
>
> The resullt from FindRoot is like:
> Out[4]:¿-> 300 000}
> how do I assign the result directly to a variable or how do I set the
> variable f to the
> resulting (root)?
>
> i.e I want to change another variable in the expression and then Plot
> the root!
Tobbe:
Plotting:
In[1]:Plot[x/.FindRoot[Tan[x]Ðf, {x,f}], {f,0,Pi/2.1}, PlotRange -> All]
On assinging to variables:
In[2]:FindRoot[Sin[x]Ð0, {x,3}]
Out[2]{x -> 3.14159}
In[3]:newvar /.%
Out[3]3.14159
In[4]:newvar
Out[4]3.14159
More directly
In[5]:newvar2 /.FindRoot[Sin[x]Ð0, {x,3}];
In[6]:newvar2
Out[6]3.14159
We can define a function of parameters
In[7]:root[a_,b_] :. FindRoot[Sin[x -b]Ð0, {x,a}]
and a version that remembers the answers
In[8]:root2[a_,b_] :¸ot2[a,b] . FindRoot[Sin[x -b]Ð0, {x,a}]
In[9]:root2[ 1,4]
Out[9]0.858407
In[10]:?root2
From In[10]:Global`root2
root2[1, 4] .8584073466995231
root2[a_, b_] :
root2[a, b] /. FindRoot[Sin[x - b] Ð0, {x, a}] --
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642