Message Boards Message Boards

How to use solution of FindRoot as the guess for the next usage of FindRoot

Posted 2 years ago

Hello Wolfram Community,

I want solve the following equations simultaneously with FindRoot:

equOne=0. + 0.0335103 p + 0.000263189 p^2 - 0.0335103 q - 0.000263189 q^2 + 
 69.5339 p (0.000435374/r + (9.11845*10^-6 p)/r) + (
 1.8068 (1 + 0.0167552 p + 0.00017546 p^2))/r + Log[1. p] - Log[q];
equTwo=0. + 0.0335103 p + 0.000263189 p^2 - 0.0335103 q - 0.000263189 q^2 + 
 27.646 p (0.000435374/r + (9.11845*10^-6 p)/r) + (
 0.718367 (1 + 0.0167552 p + 0.00017546 p^2))/r + Log[1. p] - Log[q];

For this, I incrementally increase q and use it as the initial guess for p, howeve I use a fixed value of r as the initial guess for r, i.e. rInitialGuess:

rInitialGuess=4;
solQPR=Table[Flatten@{q, {p, r} /. 
    FindRoot[{equOne == 0, 
      equTwo== 0}, {{p, q}, {r, 
       rInitialguess}}]}, {q, 0.1,100,0.1}] (*FindRoot used 1000 times*)

The general trend is this: As q increases, p also increase but r decreases. If I use the rInitialGuess for all the values of q, FindRoot cannot solve the system for large values of q since the difference between the rInitialGuess and the potential root is large. To solve this issue, i want to use the answers, i.e. solQPR[[k-1,{2,3}]] of the step k-1 as the guess for the step k; that is, use q=0.1 and r=rInitialGuess only in the first trial. How can I do that?

POSTED BY: Amir Sadeghi
2 Replies
Posted 2 years ago

Hi Hans,

Thanks for your response. It works!

Amir

POSTED BY: Amir Sadeghi

Unfortunately, my stone-age version of FindRoot (version Mathematica 7) does not find solutions to your system of equations (singular jacobian). hmm. But, perhaps the following helps a bit

Function to find its roots

ff[x_, p_, q_] := (x - p)^2 - q

start parameters: p is the shift on the x-axis, q a free parameter, xinit the 1st startparameter for FindRoot

xinit = 9; p = 5; q = 10;

now here is a fuction to find a root of the problem and update the start parameter for FindRoot

gg := Function[{x, p, q}, {q, sol = FindRoot[ff[xx, p, q], {xx, xinit}]; xinit = xx /. sol[[1]]; sol}
  ]

giving this result

Table[{xinit, gg[5, p, q]}, {q, 12, 15}]

Note how the start-parameter for FindRoot changes with increasing q.

I think you could this fit to your problem....

POSTED BY: Hans Dolhaine
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