Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Mathematica loop help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125520] Re: Mathematica loop help
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Sat, 17 Mar 2012 02:50:26 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201203150533.AAA09584@smc.vnet.net>

The solution to (a*x == 0) is zero irrespective of the value for a.
That is not very intersting.

sols = {1};
Table[{sol =
    x /. FindRoot[a*x == 0, {x, sols[[-1]]}];
   AppendTo[sols, sol]}, {a, 1, 10}];
sols = sols // Rest

{0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}

sols = FoldList[x /.
     FindRoot[#2*x == 0, {x, #1}][[1]] &,
   1, Range[10]] // Rest

{0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}

Perhaps you want to try (x - a  ==  0)

sols = {1};
Table[{sol =
    x /. FindRoot[x - a == 0, {x, sols[[-1]]}];
   AppendTo[sols, sol]}, {a, 1, 10}];
sols = sols // Rest

{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}

sols = FoldList[x /.
     FindRoot[x - #2 == 0, {x, #1}] &,
   1, Range[10]] // Rest

{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}


Bob Hanlon


On Thu, Mar 15, 2012 at 1:33 AM, Martin Scherer
<martin.scherer at gcsc.uni-frankfurt.de> wrote:
> Here is a simple example of what I'am trying to do:
> sols = {};
> Table[{sol = FindRoot[a x == 0, Drop[sols, Length[sols] - 1]];  AppendTo[sols, sol]}, {a, 1, 10}]
>
> in every iteration FindRoot should use the last solution (sol) as the new starting point for searching the new solution. The second statement Drop[...] accesses the last element inserted into sols. The third statement inserts the current solution at the end of sols.
>
> But given example leads to an infinite recursion. I do not understand why.
>
> Any help appropriated.
>
> Greetings,
> Martin
>



  • Prev by Date: Re: Symbolic tensor analysis in Mathematica 8
  • Next by Date: html posts
  • Previous by thread: Re: Mathematica loop help
  • Next by thread: Interactive image cropping is extremely slow