Message Boards Message Boards

1
|
6556 Views
|
5 Replies
|
6 Total Likes
View groups...
Share
Share this post:

How to improve the choice for the starting point in NSolve and FindRoot??

Posted 10 years ago

Hello colleagues!!

Please consider the following code

step = 1;    
aList = Table[step*i, {i, 3, 6}];    
Table[FindRoot[
  x^2 - aList[[i]] x + 1, {x, 0.5}],{i,1,Length[aList]}]

I execute the FindRoot command with the same value for the starting point, i.e. 0.5, in this case, for each value of the given list. But for the problem I'm solving, I want to pass a different starting point for each element of the list, as follows: the value for the starting point will be 0.5 for the first element of the list, but for the second item of the list, I want to use as starting point the result given by FindRoot obtained for the first element, and so on. So a starting point is given for the first element, but for the following ones, the starting value must be the result obtained for the previous element. I think this is a nice approach when solving numerical equations sensitive to the starting value, specially when the value of the variable 'step' is small. Thank you all for your help!!!

Daniel

POSTED BY: Daniel Branco
5 Replies

It's a different set of equations from before. In this case each one has .5 as solution and each has .5 as starting point. Since solutions and starting points are all the same, I have no idea what conclusion might be drawn from this in regards to whether the starting point is selected from prior solutions or from the initial starting point.

POSTED BY: Daniel Lichtblau
Posted 10 years ago

I didn't use explicitly the Print function, what I did was:

In[41]:= FoldList[x /. FindRoot[x - #1, {x, #1}] &, .5, Range[3, 6]]
Out[41]= {0.5, 0.5, 0.5, 0.5, 0.5}

The solution of the equation inside FindRoot is #1, and, looking the output, #1 is always 0.5... What is wrong with this reasoning??

POSTED BY: Daniel Branco

The claim about starting points is baffling (and certainly not carefully tested). Try printing the starting point at each iteration. You will notice below that starting points in each iteration come from immediately prior results.

In[74]:= FoldList[(Print[#1]; 
   x /. FindRoot[x^2 - #2*x + 1, {x, #1}]) &, .5, Range[3, 6]]

During evaluation of In[74]:= 0.5

During evaluation of In[74]:= 0.38196601125

During evaluation of In[74]:= 0.267949192431

During evaluation of In[74]:= 0.208712152522

Out[74]= {0.5, 0.38196601125, 0.267949192431, 0.208712152522, \
0.171572875254}
POSTED BY: Daniel Lichtblau
Posted 10 years ago

Thank you Daniel for your response!!, but I'm afraid that it doesn't answer what I'm asking.... I want to pass a different starting value each time that FindRoot is evaluated, and, specifically, I want to pass the last value obtained by FindRoot.

For the first value of the list, i.e. 3, the starting value of FindRoot is 0.5. The result given by FindRoot is 0.3819.... For the next value of the list (4, in this case), the starting value should be 0.3819.. and not 0.5. The starting value to find the root of the equation x^2-5x+1 should be 0.2679...., and so on... This starting value is a parameter of the FindRoot function.

The code you suggested uses 0.5 as the starting point for all evaluations of FindRoot.

POSTED BY: Daniel Branco

FoldList can be useful for this sort of thing.

FoldList[x /. FindRoot[x^2 - #2*x + 1, {x, #1}] &, .5, 
 Range[3, 6]]

(* Out[76]= {0.5, 0.38196601125, 0.267949192431, 0.208712152522, \
0.171572875254} *)
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract