(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 4.2' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 37061, 956]*) (*NotebookOutlinePosition[ 37744, 979]*) (* CellTagsIndexPosition[ 37700, 975]*) (*WindowFrame->Normal*) Notebook[{ Cell[TextData[{ "Here are some sample commands that should help you in implementing \ Newton's Method. If you are not very familiar with ", StyleBox["Mathematica", FontSlant->"Italic"], ", you should start with the \"Intro\" notebook, which covers the basic \ commands." }], "Text", FontSize->24], Cell["\<\ I'm going to implement the bisection method on the function x - cos \ x = 0, so you can see the basics of defining functions and performing a \ simple iteration.\ \>", "Text", FontSize->24], Cell["\<\ First I define f(x). Note the particular notation f[x_] used to \ define a function which is waiting to receive an input value for x. See the \ \"Intro\" notebook for more on this.\ \>", "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(f[x_] = \ x\ - \ Cos[x]\)], "Input", FontSize->24], Cell[BoxData[ \(x - Cos[x]\)], "Output", FontSize->24] }, Open ]], Cell["\<\ Here's the mini-program that does bisection, with initially a=0, \ b=1. Note that semicolons suppress output. Carriage returns or semicolons \ separate different commands. The command Do[ stuff, {i,1,15} ] does \"stuff\" when i=1, then \"stuff\" \ when i=2, etc. through i=15. Note that you can put multiple command in \ \"stuff\" using semicolons, as I do here (the c=(a+b)/2 and the If command). The command If[ condition, stuff1, stuff2] says: If \"condition\", do \ \"stuff1\"; if \"condition\" is false; do \"stuff2\". As above, you can put \ multiple commands in \"stuff1\" or \"stuff2\" using semicolons (but I don't \ do so here) At the end, I print out the final values of a and b.\ \>", "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(\(\(\(a = 0.0\ ;\)\ \[IndentingNewLine] \(b = 1.0;\)\ \[IndentingNewLine] \(Do[\[IndentingNewLine]\ \ \ \ \ \ c\ = \ \((a + b)\)/ 2; \[IndentingNewLine]\ \ \ \ \ \ If[\ \ f[c]*f[a]\ < \ 0.0, \ \[IndentingNewLine]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ b = c, \[IndentingNewLine]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ a = c\[IndentingNewLine]\ \ \ \ \ \ \ \ \ \ ]\[IndentingNewLine]\ \ \ , \ \ {i, 1, 15}\[IndentingNewLine]];\)\[IndentingNewLine] \(\({a, b}\)\(\[IndentingNewLine]\) \)\)\(\ \ \ \)\)\)], "Input", FontSize->24], Cell[BoxData[ \({0.73907470703125`, 0.739105224609375`}\)], "Output", FontSize->24] }, Open ]], Cell[TextData[{ "Now we can get a bit fancier. Let's say we wanted to use bisection to \ solve x - p cos x =0 for various values of p. We could keep changing p by \ hand over and over, but even nicer, we can let ", StyleBox["Mathematica", FontSlant->"Italic"], " do everything as a function of p.\n\nFirst we redefine f to depend on x \ and p." }], "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(f[x_, p_] = \ x\ - \ p*Cos[x]\)], "Input", FontSize->24], Cell[BoxData[ \(x - p\ Cos[x]\)], "Output", FontSize->24] }, Open ]], Cell[TextData[{ "Now we do bisection again, but this time, we tell ", StyleBox["Mathematica", FontSlant->"Italic"], " that this whole algorithm depends on p. We assign the whole algorithm to \ be the function \"bisection[p_]\". We use the colon-equals assignment to \ tell ", StyleBox["Mathematica", FontSlant->"Italic"], " to not try to evaluate anything until it receives a value for p. We wrap \ the algorithm in the Block command; the syntax is Block[ {localvars}, \ stuff], where \"localvars\" are a list of variables used by the algorithm and \ \"stuff\" is a list of commands separated by semicolons. \n\nI also made a \ few revisions to the algorithm to account for the presence of p:\n\nI write \ f[c,p] and f[a,p] instead of the old f[c] and f[a].\nI change the initial b \ from 1 to p, since f[1,p] may not be > 0, but f[p,p] is always >0.\nI set the \ number of iterations to n=Log[2,10^5(b-a)] (that's log base-2 of 10^5 (b-a)), \ to ensure that the width of the nth interval, (b-a)/2^n, is less than \ 10^(-5)." }], "Text", FontSize->24], Cell[BoxData[{ \(bisection[ p_]\ := \[IndentingNewLine]Block[\ \ \ {a, b, c, n, i}, \[IndentingNewLine]\ \ a = 0.0\ ; \ \[IndentingNewLine]\ \ b = p; \ \[IndentingNewLine]\ \ n\ = Log[2, 10^5*\((b - a)\)]; \[IndentingNewLine]\ \ Do[\[IndentingNewLine]\ \ \ \ \ \ \ \ \ c\ = \ \((a + b)\)/ 2; \[IndentingNewLine]\ \ \ \ \ \ \ \ If[\ \ f[c, p]* f[a, p]\ < \ 0.0, \ \[IndentingNewLine]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ b = c, \[IndentingNewLine]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ a = c\[IndentingNewLine]\ \ \ \ \ \ \ \ \ \ \ \ ]\[IndentingNewLine]\ \ \ \ \ \ , \ {i, 1, n}\[IndentingNewLine]\ \ ]; \[IndentingNewLine]\ \ \ \((a + b)\)/ 2\[IndentingNewLine]]\), "\[IndentingNewLine]", \(\ \ \ \)}], "Input", FontSize->24], Cell["Now we can run bisection for various values of p:", "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(bisection[1]\)], "Input", FontSize->24], Cell[BoxData[ \(0.7390823364257812`\)], "Output", FontSize->24] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(bisection[2]\)], "Input", FontSize->24], Cell[BoxData[ \(1.0298690795898438`\)], "Output", FontSize->24] }, Open ]], Cell["\<\ We can even plot the solution as a function of p (this amount to \ solving numerically the implicit equation x - p cos x = 0 for p in terms of \ x.\ \>", "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(Plot[bisection[p], {p, 0, 4}]\)], "Input", FontSize->24], Cell[GraphicsData["PostScript", "\<\ %! %%Creator: Mathematica %%AspectRatio: .61803 MathPictureStart /Mabs { Mgmatrix idtransform Mtmatrix dtransform } bind def /Mabsadd { Mabs 3 -1 roll add 3 1 roll add exch } bind def %% Graphics %%IncludeResource: font Courier %%IncludeFont: Courier /Courier findfont 10 scalefont setfont % Scaling calculations 0.0238095 0.238095 0.0147151 0.469997 [ [.2619 .00222 -3 -9 ] [.2619 .00222 3 0 ] [.5 .00222 -3 -9 ] [.5 .00222 3 0 ] [.7381 .00222 -3 -9 ] [.7381 .00222 3 0 ] [.97619 .00222 -3 -9 ] [.97619 .00222 3 0 ] [.01131 .10871 -18 -4.5 ] [.01131 .10871 0 4.5 ] [.01131 .20271 -18 -4.5 ] [.01131 .20271 0 4.5 ] [.01131 .29671 -18 -4.5 ] [.01131 .29671 0 4.5 ] [.01131 .39071 -18 -4.5 ] [.01131 .39071 0 4.5 ] [.01131 .48471 -6 -4.5 ] [.01131 .48471 0 4.5 ] [.01131 .57871 -18 -4.5 ] [.01131 .57871 0 4.5 ] [ 0 0 0 0 ] [ 1 .61803 0 0 ] ] MathScale % Start of Graphics 1 setlinecap 1 setlinejoin newpath 0 g .25 Mabswid [ ] 0 setdash .2619 .01472 m .2619 .02097 L s [(1)] .2619 .00222 0 1 Mshowa .5 .01472 m .5 .02097 L s [(2)] .5 .00222 0 1 Mshowa .7381 .01472 m .7381 .02097 L s [(3)] .7381 .00222 0 1 Mshowa .97619 .01472 m .97619 .02097 L s [(4)] .97619 .00222 0 1 Mshowa .125 Mabswid .07143 .01472 m .07143 .01847 L s .11905 .01472 m .11905 .01847 L s .16667 .01472 m .16667 .01847 L s .21429 .01472 m .21429 .01847 L s .30952 .01472 m .30952 .01847 L s .35714 .01472 m .35714 .01847 L s .40476 .01472 m .40476 .01847 L s .45238 .01472 m .45238 .01847 L s .54762 .01472 m .54762 .01847 L s .59524 .01472 m .59524 .01847 L s .64286 .01472 m .64286 .01847 L s .69048 .01472 m .69048 .01847 L s .78571 .01472 m .78571 .01847 L s .83333 .01472 m .83333 .01847 L s .88095 .01472 m .88095 .01847 L s .92857 .01472 m .92857 .01847 L s .25 Mabswid 0 .01472 m 1 .01472 L s .02381 .10871 m .03006 .10871 L s [(0.2)] .01131 .10871 1 0 Mshowa .02381 .20271 m .03006 .20271 L s [(0.4)] .01131 .20271 1 0 Mshowa .02381 .29671 m .03006 .29671 L s [(0.6)] .01131 .29671 1 0 Mshowa .02381 .39071 m .03006 .39071 L s [(0.8)] .01131 .39071 1 0 Mshowa .02381 .48471 m .03006 .48471 L s [(1)] .01131 .48471 1 0 Mshowa .02381 .57871 m .03006 .57871 L s [(1.2)] .01131 .57871 1 0 Mshowa .125 Mabswid .02381 .03821 m .02756 .03821 L s .02381 .06171 m .02756 .06171 L s .02381 .08521 m .02756 .08521 L s .02381 .13221 m .02756 .13221 L s .02381 .15571 m .02756 .15571 L s .02381 .17921 m .02756 .17921 L s .02381 .22621 m .02756 .22621 L s .02381 .24971 m .02756 .24971 L s .02381 .27321 m .02756 .27321 L s .02381 .32021 m .02756 .32021 L s .02381 .34371 m .02756 .34371 L s .02381 .36721 m .02756 .36721 L s .02381 .41421 m .02756 .41421 L s .02381 .43771 m .02756 .43771 L s .02381 .46121 m .02756 .46121 L s .02381 .50821 m .02756 .50821 L s .02381 .53171 m .02756 .53171 L s .02381 .55521 m .02756 .55521 L s .02381 .60221 m .02756 .60221 L s .25 Mabswid .02381 0 m .02381 .61803 L s 0 0 m 1 0 L 1 .61803 L 0 .61803 L closepath clip newpath .5 Mabswid .02381 .01472 m .06244 .09001 L .10458 .16597 L .14415 .22818 L .18221 .27918 L .22272 .3249 L .26171 .36191 L .30316 .39514 L .34309 .42238 L .3815 .44499 L .42237 .46592 L .46172 .48355 L .49955 .49858 L .53984 .51284 L .57861 .52512 L .61984 .53686 L .65954 .54708 L .69774 .55603 L .73838 .56473 L .77751 .5724 L .81909 .57989 L .85916 .58654 L .89771 .59247 L .93871 .59833 L .97619 .60332 L s % End of Graphics MathPictureEnd \ \>"], "Graphics", ImageSize->{444, 274.313}, ImageMargins->{{43, 0}, {0, 0}}, ImageRegion->{{0, 1}, {0, 1}}, FontSize->72, ImageCache->GraphicsData["Bitmap", "\<\ CF5dJ6E]HGAYHf4PAg9QL6QYHgKP2/c81Q0>K@00000j0:cKJdCP10>Dh0i/b0 0>KKKKKJI>P000000JIV006<0i/b000<0[5d00000001YVH00H@3Vc8001P3Vc600J@0000000000 0000000S08fdP0T0i/b0001l0>KJI>P10OG00i/b006D0i/b000<0i/aP0:bIP03Vc800H`3V c8000`3Vc600JCU>0>KKKP2/ VCX0@7e`06<0i/b000H0i[A>040iCP3Vc800i/aP06T0>P2/c81P0>KKK< H01Y03X0[P10OG0:0>KK040000000000JIV0H`3Vc8000`3V]4h0@000 041mL00:0>KKKKK< P0030000003Vc800i/b00?l0i/b0X`3Vc80001L0i/b000<000000>KKKKKKKKK< P:<0i/b0000=0>KKKKKKKKKKKKKKKKKKKKKKKKKKKKKK< P:<0i/b0000G0>KKKKKKKKKKKKKKKKK< P0030000003Vc800i/b000@0i/b000<000000>KKKKKKKKKKKKKKK< P9T0i/b0000G0>KKKKKK< P0080>KKKKKK< P03Vc800o`3Vc82G0>KKKKKKKKKKKK< P03Vc800303Vc8000`000000i/b00>KKKKKKKKKKKKK< P0030000003Vc800i/b000l0i/b000<000000>KKKKKKKKKKKKKKJI>P00000000000000000003X0[KKKKCX0[@00 000j0:cKK0>KKJI>P000000JIV000H0i/b01000000B0>K< P0030000003Vc800i/b00?l0i/b0S@3Vc80000060>KDh0i/b00>KKKKKP2/c8060>KJdCP10>Dh0i/b00>KKKK< P03V]4h0@0000000001YVH00203Vc800103:OB<0000000000010OG060>KKKKKKKKKKKKKKKKKKKKKKKKKKKKK< P0005`3Vc8000`000000i/b00>KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK< P0005`3Vc8000`000000i/b00>KKKKKKKKKKKKKKK0>KKKKDh0i/b00>KKKDh0i/b0 0>KJI>P10OG060>KKKP2/c8070>KKKKK< P7D0i/b000001@3Vc800i[A>040000000000JIV000T0i/b000<0i[A>04000010OG001P3Vc8000`00 0000i/b00>KKKKKKKKKKKKKKKK< P0005`3Vc8000`000000i/b00>KKKKKKKKKKKKKKKKKKKKKKKKKKKKK03Vc8000`000000i/b00>KKKKKKKKP3Vc8000`000000i/b00>KKKKKKKKKKKKK< P0005`3Vc8000`000000i/b00>KKKKKKKKKKKKKKKKKKKKKKKKKK< P0030>K00<0i/b000D0i/aP06T000000000000S08fdP0050>KKKP2/ c8070>KKKKKDh0i/b00>KKKDh0i/b00>KCX0@3T000000000>Dh60>KKKP2/c8070>KJI>P00>Dh0i/b000L0i/b000<000000>KKK040000000000JIV000T0i/b000@0bWdS00000000 0000JIV01@3Vc8000`000000i/b00>KKKKKKKKK< P01>0>KKKKKK< P03Vc800o`3Vc81A0>KKKKKKKKKKKK< P0030000003Vc800i/b00?l0i/b0C03Vc80001L0i/b000<000000>KKKKKKKKKKKK< P0030000003Vc800i/b005T0i/b000<000000>KKKKKKK< P03o0>KKKKKKKKKKKKK< P01Q0>KKKKKK< P03Vc800o`3Vc80m0>KKKKKK< P01W0>K@3Vc80001L0i/b000<000000>KKKKK< P3P0i/b0000G0>KKKKKKKKKKDh00`3Vc800102/G@00000000000010OG060>KKKP2/c8060>KK< H01YGF00i/b00>KKKKDh0i/b00>KKKKDh0i/b00>KKKKP2/c8060>KKDh0i/b00>K< H01Y>Dh01P3Vc8000`000000i/b00>KKKKKKK< P03Vc800o`3Vc80X0>KKKKKKKKKKK< P03Vc800o`3Vc80Q0>KKKKKK< P0230>KKKKK< P1X0i/b0000G0>KKKKKKKKK< P0030000003Vc800i/b008l0i/b00P00003o0>KKKKKKKKK< P0T0i/b0000G0>KKKKKKKKK< P0030000003Vc800i/b00:80i/b00P00003n0>KKKKKKKKKKKKK< P02b0>KKKKKKKKL0i/b0000>0>KJI>P10OG00i/b000H0i/b000<000000>KD0i/b0000=0>KP2/VCX0@7e`00L0i/b000<000000>K80 i/b0000=0>KJI>P000000@7e`00L0i/b000<000000>KKKKKKKKK0>KKKKKKKKKKKKKKL0i/b00`00002h0>KKKKKKKKKKKKKKKKKK< P0<00000o`3Vc80M0>KKKKKKKKKKKKKKKKKP2/c8050>KKJI>P10OG00i/b000P0i/b000<0SCT00000>P2/c8001`3V c8000`000000i/b00>KKKKKJI>P000000JIV000H0i/b01000003o0>KKKKKKK< P0H00000AP3Vc80000040>KCX0[9Tj041mL0P0i/b000H0i[A>040iCP3Vc800i/aP06T0>P2/ c8050>KKKK`3Vc80001L0i/b000<000000>KKKKKK< P0L00000:@3Vc80001L0i/b000<000000>KKKKKKKKKKKKKKKKKK< P000\ \>"], ImageRangeCache->{{{0, 443}, {273.313, 0}} -> {-0.231805, -0.071207, \ 0.0097855, 0.00495722}}], Cell[BoxData[ TagBox[\(\[SkeletonIndicator] Graphics \[SkeletonIndicator]\), False, Editable->False]], "Output", FontSize->24] }, Open ]], Cell[TextData[{ "When implementing Newton's method, you will need derivatives of functions. \ You can, of course, do this by hand, or you can let ", StyleBox["Mathematica", FontSlant->"Italic"], " do it using the \"D\" command:" }], "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(f[x_, p_] = \ x\ - p*\ Cos[x]\)], "Input", FontSize->24], Cell[BoxData[ \(x - p\ Cos[x]\)], "Output", FontSize->24] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(dfdx[x_, p_]\ = \ D[f[x, p], x]\)], "Input", FontSize->24], Cell[BoxData[ \(1 + p\ Sin[x]\)], "Output", FontSize->24] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(dfdp[x_, p_]\ = \ D[f[x, p], p]\)], "Input", FontSize->24], Cell[BoxData[ \(\(-Cos[x]\)\)], "Output", FontSize->24] }, Open ]], Cell[TextData[{ "When implementing Newton's method, you will have to program the step ", Cell[BoxData[ \(TraditionalForm\`x\_\(k + 1\)\)]], " = ", Cell[BoxData[ \(TraditionalForm\`x\_k\)]], " - f(", Cell[BoxData[ \(TraditionalForm\`x\_k\)]], ")/f'(", Cell[BoxData[ \(TraditionalForm\`x\_k\)]], "). You can actually use the same variable name for ", Cell[BoxData[ \(TraditionalForm\`\(\(x\_\(k + 1\)\ as\ you\ use\ for\ x\_k\)\(,\)\(\ \ \)\(since\)\(\ \)\)\)]], "you don't need to reuse ", Cell[BoxData[ \(TraditionalForm\`x\_k\)]], ". So, assuming you have defined functions f[x] and dfdx[x], you can just \ do x = x - f[x]/dfdx[x]:" }], "Text", FontSize->24], Cell[CellGroupData[{ Cell[BoxData[ \(f[x_]\ = \ x^2\)], "Input", FontSize->24], Cell[BoxData[ \(x\^2\)], "Output", FontSize->24] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(dfdx[x_]\ = \ D[f[x], x]\)], "Input", FontSize->24], Cell[BoxData[ \(2\ x\)], "Output", FontSize->24] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(x\ = \ 2\)], "Input", FontSize->24], Cell[BoxData[ \(2\)], "Output", FontSize->24] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(x\ = \ x\ - \ f[x]/dfdx[x]\)], "Input", FontSize->24], Cell[BoxData[ \(1\)], "Output", FontSize->24] }, Open ]], Cell["\<\ When implementing Newton's method in n dimensions, you can use \ almost the same code if you set things up as vector functions. Here's the \ example I did in class: \ \>", "Text", FontSize->24], Cell["\<\ Here are our two functions. We want to solve f1=0,f2=0 \ simultaneously for x and y.\ \>", "Text", FontSize->24], Cell[BoxData[{ \(\(f1[x_, y_]\ = \ x + y + Cos[x\^2 + y\^2];\)\), "\[IndentingNewLine]", \(\(f2[x_, y_]\ = \ 2*x*y - Sin[x\^2 - y\^2];\)\)}], "Input", FontSize->24], Cell["\<\ Here's the vector function we're looking to set equal to zero. \ \ \>", "Text", FontSize->24], Cell[BoxData[ \(f[x_, y_]\ = \ {f1[x, y], f2[x, y]}\)], "Input", FontSize->24], Cell["Here's the Jacobian. ", "Text", FontSize->24], Cell[BoxData[ RowBox[{\(J[x_, y_]\), " ", "=", " ", RowBox[{"(", GridBox[{ {\(D[f1[x, y], x]\), \(D[f1[x, y], y]\)}, {\(D[f2[x, y], x]\), \(D[f2[x, y], y]\)} }], ")"}]}]], "Input", FontSize->24], Cell[TextData[{ "Here's a version of f that accepts as input a vector v. That will make \ the Newton's method code nicer (\"vector version\"). Notice \"Block\" to run \ a set of commands at once. Notice the := (\"delayed evaluation\") . That \ tells ", StyleBox["Mathematica", FontSlant->"Italic"], " not to try to compute anything until a specific v is plugged in. Right \ now it doesn't know what to make of v[[1]] and v[[2]], the first and second \ slots of the vector v." }], "Text", FontSize->24], Cell[BoxData[ \(fvec[v_]\ := \ f[\ v[\([1]\)], \ v[\([2]\)]\ ]\)], "Input", FontSize->24], Cell["\<\ Similarly, here's a version of J that accepts as input a vector v. \ \ \>", "Text", FontSize->24], Cell[BoxData[ \(Jvec[v_]\ := \ J[\ v[\([1]\)], \ v[\([2]\)]\ ]\)], "Input", FontSize->24], Cell[TextData[{ "Now let's run Newton's method. I use initial guess {x,y}={-1/2,0}. My \ stopping condition is that the length of f is less than ", Cell[BoxData[ \(TraditionalForm\`10\^\(-12\)\)]], ". Notice the use of LinearSolve to compute ", Cell[BoxData[ \(TraditionalForm\`J\^\(-1\)\)]], "f. " }], "Text", FontSize->24], Cell[BoxData[{ \(\(v\ = \ {\(-0.5\), 0.0};\)\), "\[IndentingNewLine]", \(\(Print[{"\<{x,y}\>", "\"}];\)\), "\[IndentingNewLine]", \(\(Print[v, "\<,\>", fvec[v]];\)\), "\[IndentingNewLine]", \(While[\@\(fvec[v] . fvec[v]\) > \ 10\^\(-12\), \[IndentingNewLine]v\ = \ v\ - \ LinearSolve[Jvec[v], fvec[v]]; \[IndentingNewLine]Print[ v, "\<,\>", fvec[v]]\[IndentingNewLine]]\), "\[IndentingNewLine]", \(\)}], "Input", FontSize->24], Cell["\<\ Where did I get that initial guess from? Well, a contour plot of \ the two functions, with only the zero contour plotted, gives useful \ information: \ \>", "Text", FontSize->24], Cell[BoxData[{ \(plot1 = ContourPlot[f1[x, y], {x, \(-3\), 3}, {y, \(-3\), 3}, Contours \[Rule] {0}, PlotPoints \[Rule] 50, ContourShading \[Rule] False]\), "\[IndentingNewLine]", \(plot2 = ContourPlot[f2[x, y], {x, \(-3\), 3}, {y, \(-3\), 3}, Contours \[Rule] {0}, PlotPoints \[Rule] 50, ContourShading \[Rule] False, ContourStyle \[Rule] RGBColor[1, 0, 0]]\), "\[IndentingNewLine]", \(Show[plot1, plot2]\)}], "Input", FontSize->24] }, FrontEndVersion->"4.2 for Microsoft Windows", ScreenRectangle->{{0, 1400}, {0, 967}}, WindowSize->{962, 737}, WindowMargins->{{42, Automatic}, {Automatic, 15}}, StyleDefinitions -> "PastelColor.nb" ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1754, 51, 309, 8, 107, "Text"], Cell[2066, 61, 201, 5, 74, "Text"], Cell[2270, 68, 222, 5, 74, "Text"], Cell[CellGroupData[{ Cell[2517, 77, 73, 2, 49, "Input"], Cell[2593, 81, 60, 2, 49, "Output"] }, Open ]], Cell[2668, 86, 741, 16, 404, "Text"], Cell[CellGroupData[{ Cell[3434, 106, 620, 12, 423, "Input"], Cell[4057, 120, 89, 2, 49, "Output"] }, Open ]], Cell[4161, 125, 384, 9, 173, "Text"], Cell[CellGroupData[{ Cell[4570, 138, 79, 2, 49, "Input"], Cell[4652, 142, 63, 2, 49, "Output"] }, Open ]], Cell[4730, 147, 1076, 20, 437, "Text"], Cell[5809, 169, 903, 18, 559, "Input"], Cell[6715, 189, 81, 1, 41, "Text"], Cell[CellGroupData[{ Cell[6821, 194, 61, 2, 49, "Input"], Cell[6885, 198, 69, 2, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[6991, 205, 61, 2, 49, "Input"], Cell[7055, 209, 69, 2, 49, "Output"] }, Open ]], Cell[7139, 214, 187, 5, 74, "Text"], Cell[CellGroupData[{ Cell[7351, 223, 78, 2, 49, "Input"], Cell[7432, 227, 23864, 499, 291, 3430, 241, "GraphicsData", "PostScript", \ "Graphics"], Cell[31299, 728, 146, 4, 49, "Output"] }, Open ]], Cell[31460, 735, 267, 7, 74, "Text"], Cell[CellGroupData[{ Cell[31752, 746, 79, 2, 49, "Input"], Cell[31834, 750, 63, 2, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[31934, 757, 81, 2, 49, "Input"], Cell[32018, 761, 63, 2, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[32118, 768, 81, 2, 49, "Input"], Cell[32202, 772, 61, 2, 49, "Output"] }, Open ]], Cell[32278, 777, 725, 23, 140, "Text"], Cell[CellGroupData[{ Cell[33028, 804, 64, 2, 49, "Input"], Cell[33095, 808, 54, 2, 50, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[33186, 815, 74, 2, 49, "Input"], Cell[33263, 819, 54, 2, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[33354, 826, 58, 2, 49, "Input"], Cell[33415, 830, 51, 2, 49, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[33503, 837, 77, 2, 49, "Input"], Cell[33583, 841, 51, 2, 49, "Output"] }, Open ]], Cell[33649, 846, 207, 5, 74, "Text"], Cell[33859, 853, 125, 4, 41, "Text"], Cell[33987, 859, 186, 4, 85, "Input"], Cell[34176, 865, 106, 4, 41, "Text"], Cell[34285, 871, 85, 2, 49, "Input"], Cell[34373, 875, 54, 1, 41, "Text"], Cell[34430, 878, 243, 6, 74, "Input"], Cell[34676, 886, 518, 11, 173, "Text"], Cell[35197, 899, 96, 2, 49, "Input"], Cell[35296, 903, 110, 4, 41, "Text"], Cell[35409, 909, 96, 2, 49, "Input"], Cell[35508, 913, 351, 10, 74, "Text"], Cell[35862, 925, 490, 9, 301, "Input"], Cell[36355, 936, 191, 5, 74, "Text"], Cell[36549, 943, 508, 11, 219, "Input"] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)