Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I've had some fun playing around with FindRootPlot for a simple system of equations:

<< Optimization`UnconstrainedProblems`
f[1] = Sin[x[1] + x[2]]
f[2] = Cos[x[1] - x[2]]
F = Table[f[i], {i, 1, 2}]

guess[1] = 1;
guess[2] = -1;

Xinsert = Table[{x[i], guess[i]}, {i, 1, 2}]

FindRootPlot[F, Xinsert, Method -> {"Newton", 
"StepControl{"LineSearch","MaxRelativeStepSize" -> .1}}]

Which gives a plot

Mathematica graphics

and the following:

{{x[1] -> 0.785398, x[2] -> -0.785398}, {"Steps" -> 5,"Residual" -> 5, "Jacobian" -> 4},

But when I tried applying it to a larger matrix it seems to no longer work. Given:

dim = 8; 

test4 ={0.3125 z[5] + 0.4375 z[6] + 0.0706277 z[7] + 0.101342 z[8], 0.5 z[7] + 1.   
z[8], -0.961887 z[1] - 1.35898 z[2] - 0.29427 z[3] - 0.415442 z[4], -3.30241 z[1] - 
6.60482 z[2], -2.77806 z[5] - 3.90146 z[6] - 0.671632 z[7] - 0.943006 z[8] + 1.875 
z[1] z[9] + 2.625 z[2] z[9] + z[3] (-1.83751 + 1.875 z[9]) + z[4] (-2.58057 + 2.625 
z[9]), -1.95073 z[5] - 2.77806 z[6] - 0.471503 z[7] - 0.671632 z[8] + 1.3125 z[1] 
z[9] + 1.875 z[2] z[9] + z[3] (-1.29029 + 1.3125 z[9]) + z[4] (-1.83751 + 1.875   
z[9]), z[6] (-10.1813 - 2.54697 z[9]) + z[5] (-7.27566 - 1.83285 z[9]) + 2.42463 
z[1] z[9] + 3.36932 z[2] z[9] + 1.01633 z[7] z[9] + 1.42194 z[8] z[9] + z[3]  
(-2.74994 + 2.42463 z[9]) + z[4] (-3.84816 + 3.36932 z[9]), z[6] (-7.27566 - 1.83285 
z[9]) + z[5] (-5.09064 - 1.27349 z[9]) + 1.68466 z[1] z[9] + 2.42463 z[2] z[9] + 
0.710972 z[7] z[9] + 1.01633 z[8] z[9] + z[3] (-1.92408 + 1.68466 z[9]) + 
z[4] (-2.74994 + 2.42463 z[9]), -1 + z[3]/2 + z[4] + z[5] + z[6]}

and

Esol2 = AppendTo[Esol, 1]

(* {-5.15989, 2.57995, 12.036, -5.01798, 0.391302, -0.357324,1.70608,     
-0.85304, 1} *)

and

Dimensions[Esol2]

(* {9} *)

I can explain where Esol and test4 come from if needed but I didn't want to clutter the post with too much information. For now I just want to point out that they are lists of length 9.

Now I try to use FindRootPlot:

F = Table[test4[[i]], {i, 1, dim + 1}];

Dimensions[F]

(* {9} *)

Xinsert = Table[{z[i], Esol[[i]]}, {i, 1, dim + 1}]

(* {{z[1], -5.15989}, {z[2], 2.57995}, {z[3], 12.036}, {z[4], -5.01798},    
{z[5], 0.391302}, {z[6], -0.357324}, {z[7], 1.70608}, {z[8], -0.85304}, {z[9], 1}} *)

Dimensions[Xinsert]

(* {9, 2} *)

FindRootPlot[F, Xinsert,Method -> {"Newton", "StepControl" -> {"LineSearch",   
"MaxRelativeStepSize" -> .1}}]

Which gives me an error about the number of equations not being equal to the number of variables. But this makes no sense the length of Xinsert and F are clearly equal. Running the previous command also gives this:

FindRoot[Optimization`UnconstrainedProblems`Private`obj, {{z[1], -5.15989}, {z[2],     
2.57995}, {z[3],12.036}, {z[4], -5.01798}, {z[5], 0.391302}, {z[6], -0.357324},    
{z[7], 1.70608}, {z[8], -0.85304}, {z[9],1}}, {"Jacobian" -> {"Symbolic", 
EvaluationMonitor :> 
Sow[{{z[1],-5.15989},Optimization`UnconstrainedProblems`Private`obj},{Optimization`UnconstrainedProblems`Private`j$37945,Optimization`UnconstrainedProblems`Private`all$37945}]}, Method -> {"Newton", "StepControl" -> {"LineSearch", "MaxRelativeStepSize" -> 0.1}}, "StepMonitor" :> Sow[{{z[1], -5.15989},    Optimization`UnconstrainedProblems`Private`obj}, \
{Optimization`UnconstrainedProblems`Private`s$37945, 
     Optimization`UnconstrainedProblems`Private`all$37945}], 
  "EvaluationMonitor" :> 
   Sow[{{z[1], -5.15989}, 
     Optimization`UnconstrainedProblems`Private`obj}, \
{Optimization`UnconstrainedProblems`Private`r$37945, 
     Optimization`UnconstrainedProblems`Private`all$37945}]}]
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

FindRootPlot[] supports only 1D and 2D problems:

FindRootPlot[f,{{x,Subscript[x, st]},{y,Subscript[y, st]}},opts] plot the steps and the points at which the function f and any of its derivatives that were evaluated in FindRoot[f,{{x,Subscript[x, st]},{y,Subscript[y, st]}}], superimposed on a contour plot of the merit function f as a function of x and y; opts may include options from both FindRoot and ContourPlot

How could it plot the problem in more dimensions?

share|improve this answer
    
You can apply FindRoot (without the Plot) in as many dimensions as needed. Then plot the roots as you wish. –  bill s Oct 30 '13 at 2:26
    
Crap, I feel like such an idiot. Thanks for clearing this up. –  tau1777 Oct 30 '13 at 2:33
    
@tau1777 If only they give me one cent for each time I feel like that ... –  belisarius Oct 30 '13 at 2:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.