[Date Index]
[Thread Index]
[Author Index]
Re: FindRoot: Slight variation of usage
*To*: mathgroup at christensen.cybernetics.net
*Subject*: [mg1730] Re: [mg1709] FindRoot: Slight variation of usage
*From*: John Fultz <jfultz>
*Date*: Fri, 21 Jul 1995 00:46:40 -0400
> Hi,
> I've got a quick question. I want to use FindRoot to find
> the root of a multi-variable function, e.g.
> f[x1_,x2_] := x2 + Cos[x1]
> for a _fixed_ value of the other variables (x2=constant) and
> find the root in the (only) remaining variable, x1. How should
> I do this for many different realizations of the other variables?
>
> Thanks,
> John
>
> P.S. As an aside, I wrote my own program that combines Newton-
> Raphson root finding with the bisection method to guarantee
> a root (provided it is bracketed) in the interval. FindRoot
> sometimes returned roots out of my xstart,xend domain. I am
> actually using this program in the above question, but thought
> the procedure would be the same.
>
> ________________________________________________________________________
> John D. Corless
> Institute of Optics (716) 275-8006 phone
> University of Rochester (716) 244-4936 fax
> Rochester, NY 14627 corless at optics.rochester.edu
> ________________________________________________________________________
Assuming that you have a prepared list of values, you could do something
like the following:
In[1]:= f[x1_,x2_] := x2 + Cos[x1] (* your function *)
In[2]:= l = {.5,.8,.95,1}; (* a sample list of numbers *)
In[3]:= g[x2_] := FindRoot[f[x1,x2] == 0, {x1, 1}] (* this function takes
the constant as its argument *)
In[4]:= Map[g,l] (* Now map it over your list *)
Out[4]= {{x1 -> 2.0944}, {x1 -> 2.49809}, {x1 -> 2.82403},
{x1 -> 3.14099}}
If you want to use multiple variables, then you could do:
In[5]:= f[x1_, x2_, x3_] := x3 + x2 * Cos[x1]
In[6]:= l={{.6,.3},{.5,.5},{.4,.2}}; (* list of constants in the
format {x2,x3} *)
In[7]:= g[{x2_,x3_}] := FindRoot[f[x1,x2,x3] == 0, {x1, 1}]
In[8]:= Map[g,l]
Out[8]= {{x1 -> 2.30052}, {x1 -> 3.14099}, {x1 -> 2.0944}}
John Fultz
Wolfram Research, Inc.
Prev by Date:
**Memory Question**
Next by Date:
**[ ] { } etc on OSF1 LK-401 AG Keyborad**
Previous by thread:
**FindRoot: Slight variation of usage**
Next by thread:
**Definite integral difficulty**
| |