Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Recursive FindRoot with initial values as a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77047] Re: Recursive FindRoot with initial values as a list
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 1 Jun 2007 02:48:59 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f3m4qv$fgl$1@smc.vnet.net>

R.G wrote:
> Greetings...
> Say I have a function defined as:
> f[a_, b_]:= Integrate[Sin[x] + 3, {x, a, b}]
> 
> I can find b with given f[a,b]=2 and initial value=0:
> In[1]:= Initialvalue = 0;
>      s1 = FindRoot[f[0, unknown] == 2, {unknown,Initialvalue}];
>      x1 = s1[[ 1, 2]]
> 
> Now, using the x1 value obtained from FindRoot, I can find x2:
>      s2 = FindRoot[f[x1, unknown] == 2, {unknown,Initialvalue}];
>      x2 = s2[[ 1, 2]]
> 
> If I have initialvalue in a list form:
> InitialValues={initialvalue1,initialvalue2,...,initialvalueN} 
> 
> in which each si should get InitialValues[[i]], in general form:
> 
> \!\(s\_i = 
>     FindRoot[{f[x\_\(i - 1\), unknown] \[Equal] 2}, {unknown, 
>         InitialValues[\([i]\)]}]\)
> 
> where
> 
> \!\(x\_i = s\_i[\([1, 2]\)]\)
> 
> How do I code it in Mathematica please? Thanking in advance...
> 
> ~R.G

Hi,

One possible way of doing what you are looking for is the use a 
functional construct such as NestList and a pure function (that why you 
can see #1 and &). For instance,

In[1]:= f[a_, b_] = Integrate[Sin[x] + 3, {x, a, b}];
   With[{Initialvalue = 0, n = 5},
     Rest[NestList[FindRoot[f[#1, unknown] == 2,
               {unknown, Initialvalue}][[1, 2]] & , 0, n]]]

Out[1]= {0.607102, 1.13938, 1.64271, 2.15069, 2.69881}

Cheers,
Jean-Marc


  • Prev by Date: Re: [V6.0] Possible bug found in Symbolize (Notation Palette)
  • Next by Date: Re: Iterating List
  • Previous by thread: Re: Recursive FindRoot with initial values as a list
  • Next by thread: Re: Recursive FindRoot with initial values as a list