Help needed with FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg17210] Help needed with FindRoot
- From: "Alejandro Jara" <ajara at ucla.edu>
- Date: Mon, 26 Apr 1999 01:20:47 -0400
- Sender: owner-wri-mathgroup at wolfram.com
I would really appreciate if someone has the time to take a look to my program where I try to plot a set of solutions from a system of equations using the FindRoot command, unfortunately the method does not converge easily, so I need to make the grid very small, but that cause my computer to crash, I guess due to memory problems. Does anybody has a suggestion how to make my program more efficient? Thanks very much, aj ************************************************** Alejandro Jara Department of Economics, UCLA ajara at ucla.edu (310) 478-6184 ************************************************** (*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 3.0, MathReader 3.0, or any compatible application. The data for the notebook starts with the line of 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 at 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[ 15161, 364]*) (*NotebookOutlinePosition[ 16112, 396]*) (* CellTagsIndexPosition[ 16068, 392]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData["The Exogenous tau: \[Sigma] = 1 case"], "Section", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(ClearAll[T, mo, mT, hT, \[Mu]T, zT, c0, cT, K0KT, B0, BT, h0, z0, iT, igT, L0, LT, \[Mu]0, jump, W, fallinc, iTminusigT, eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10, eq11, eq12, eq13, eq14, eq15, eq16, eq17, eq18, eq19, eq20, eq21, values, initial]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \({r, q, \ taubar} = {0.0041, \ 0.5, 3.508995}; \n{\[Alpha], \ \[Theta]}\ = \ {1.5, 1.55}; \n{i0, \ ig0}\ = \ {r, \ 0.002}; \n{Q} = \ {\((1 - q)\)/q}; \n{R0}\ = \ {1070.52}; \n{initialprimarydeficit}\ = \ {taubar\ - r*R0}; \n igT[\[Gamma]_] := \ \ ig0\ + \ \[Gamma]*\[Mu]T; \)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(eq1[\[Gamma]_] := taubar\ == \ r*R0\ + \ Exp[\(-r\)*T]* \((\[Mu]T*hT\ + \ \((\[Mu]T*\((1 - \[Gamma])\) - ig0)\)*zT)\) - Exp[\(-r\)*T]*r*\((m0\ - \ mT)\)\n\t\t - \((1 - \ Exp[\(-r\)*T])\)*ig0*z0; \n eq2[\[Gamma]_] := taubar\ == \ \[Mu]T*hT\ + \ \((\[Mu]T*\((1 - \[Gamma])\) - ig0)\)*zT; \neq3 = c0/cT\ == \ 1; \n eq4 = c0*\((1 - Exp[\(-r\)*T])\)\ + \ cT*Exp[\(-r\)*T]\ == 100; \n eq5 = B0\ == \ \((h0^\((1 - \[Theta])\))\)/\((1 - \[Theta])\)\ + \ \((z0^\((1 - \[Alpha])\))\)/\((1 - \[Alpha])\); \n eq6 = BT\ == \ \((hT^\((1 - \[Theta])\))\)/\((1 - \[Theta])\)\ + \ \((zT^\((1 - \[Alpha])\))\)/\((1 - \[Alpha])\); \n eq7 = h0\ == \ \t\((Q*c0/r)\)^\((1/\[Theta])\); \n eq8 = z0\ == \ \t\((Q*c0/\((i0 - ig0)\))\)^\((1/\[Alpha])\); \n eq9 = hT\ == \ \ \((Q*cT/\((iT)\))\)^\((1/\[Theta])\); \n eq10[\[Gamma]_]\ := zT == \ \((Q*cT/\((iT - igT[\[Gamma]])\))\)^\((1/\[Alpha])\); \n eq11 = m0\ == \ h0\ + z0; \neq12 = mT\ == \ hT\ + zT; \n eq13 = L0\ == \ Exp[B0]; \neq14 = LT\ == \ Exp[BT]; \n eq15 = iT\ == \ r\ + \ \[Mu]T; \n eq16 = \[Mu]0\ == \ \((taubar\ + ig0*z0 - \ r*R0)\)/\((m0 - R0)\); \n eq17 = jump\ == \ \((m0\ - \ mT)\)/100; \n eq18 = W\ == \ \((q*Log[c0] + \((1 - q)\)*Log[L0])\)*\((1 - Exp[\(-r\)*T])\) + q*Log[cT] + \((1 - q)\)*Log[LT]*Exp[\(-r\)*T]; \n eq19 = fallinc == \((c0 - cT)\); \n eq20[\[Gamma]_] := iTminusigT\ == \ iT - igT[\[Gamma]]; \t\t\)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(start[\[Gamma]_] := FindRoot[{eq1[\[Gamma]], eq2[\[Gamma]], eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10[\[Gamma]], eq11, eq12, eq13, eq14, eq15, eq16, eq17, eq18, eq19, eq20[\[Gamma]]}, \n \t\t{c0, 100\ }, {cT, \ 97}, {B0, \(-0.1\)}, {BT, \(-0.2\)}, {m0, 1893}, {mT, 1623}, {L0, 0.89}, {LT, 0.814}, {iT, 0.06}, {\[Mu]0, 0.001}, {iTminusigT, 0.001}, {T, 318}, {W, 4.11}, {fallinc, 3.19}, { jump, 2.7}, {h0, 845}, {hT, 134}, {z0, 1047}, {zT, 1488}, {\[Mu]T, 0.05}, \ MaxIterations -> 10000, Compiled -> True]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(lowerlimit = start[0]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(initial = {c0ini \[Rule] c0, cTini \[Rule] cT, B0ini \[Rule] B0, BTini \[Rule] BT, m0ini \[Rule] m0, mTini \[Rule] mT, L0ini \[Rule] L0, LTini \[Rule] LT, iTini \[Rule] iT, \[Mu]0ini \[Rule] \[Mu]0, iTminusigTini \[Rule] iTminusigT, Tini \[Rule] T, Wini\n\t\t \[Rule] W, fallincini \[Rule] fallinc, jumpini \[Rule] jump, h0ini \[Rule] h0, hTini \[Rule] hT, z0ini \[Rule] z0, zTini \[Rule] zT, \[Mu]Tini \[Rule] \[Mu]T} /. lowerlimit; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(sol[\[Gamma]_] := Module[{values}, \n\t\t values = FindRoot[{eq1[\[Gamma]], eq2[\[Gamma]], eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10[\[Gamma]], eq11, eq12, eq13, eq14, eq15, eq16, eq17, eq18, eq19, eq20[\[Gamma]]}, \n \t\t{c0, c0ini} /. initial, {cT, \ cTini} /. initial, {B0, B0ini} /. initial, {BT, BTini} /. initial, {m0, m0ini} /. initial, {mT, mTini} /. initial, {L0, L0ini} /. initial, {LT, LTini} /. initial, {iT, iTini} /. initial, {\[Mu]0, \[Mu]0ini} /. initial, {iTminusigT, iTminusigTini} /. initial, {T, Tini} /. initial, {W, Wini} /. initial, {fallinc, fallincini} /. initial, {jump, jumpini} /. initial, {h0, h0ini} /. initial, {hT, hTini} /. initial, {z0, z0ini} /. initial, {zT, zTini} /. initial, {\[Mu]T, \[Mu]Tini} /. initial, \ MaxIterations -> 1000, AccuracyGoal -> 5, Compiled -> True]; \n\t\t initial = {c0ini \[Rule] c0, cTini \[Rule] cT, B0ini \[Rule] B0, BTini \[Rule] BT, m0ini \[Rule] m0, mTini -> mT, L0ini \[Rule] L0, LTini \[Rule] LT, iTini \[Rule] iT, \[Mu]0ini \[Rule] \[Mu]0, iTminusigTini \[Rule] iTminusigT, Tini \[Rule] T, Wini \[Rule] W, fallincini \[Rule] fallinc, jumpini \[Rule] jump, h0ini \[Rule] h0, hTini \[Rule] hT, z0ini \[Rule] z0, zTini \[Rule] zT, \[Mu]Tini \[Rule] \[Mu]T} /. values; \n \t\t{{\[Gamma], c0}, {\[Gamma], cT}, {\[Gamma], B0}, {\[Gamma], BT}, { \[Gamma], m0}, {\[Gamma], mT}, {\[Gamma], L0}, {\[Gamma], LT}, { \[Gamma], iT}, {\[Gamma], \[Mu]0}, {\[Gamma], iTminusigT}, { \[Gamma], T}, {\[Gamma], W}, {\[Gamma], fallinc}, {\[Gamma], jump}, {\[Gamma], h0}, {\[Gamma], hT}, {\[Gamma], z0}, { \[Gamma], zT}, {\[Gamma], \[Mu]T}} /. values\n\t\t]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(m1 = Table[sol[\[Gamma]], {\[Gamma], 0, 1, 0.001}]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(m2 = Table[sol[\[Gamma]], {\[Gamma], 1, 1.18, 0.00001}]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p1 = ListPlot[Join[Re[\(Transpose[m1]\)[\([1]\)]], Re[\(Transpose[m2]\)[\([1]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<c0\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p2 = ListPlot[Join[Re[\(Transpose[m1]\)[\([2]\)]], Re[\(Transpose[m2]\)[\([2]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<cT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p3 = ListPlot[Join[Re[\(Transpose[m1]\)[\([3]\)]], Re[\(Transpose[m2]\)[\([4]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<B0\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p4 = ListPlot[Join[Re[\(Transpose[m1]\)[\([4]\)]], Re[\(Transpose[m2]\)[\([5]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<BT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p5 = ListPlot[Join[Re[\(Transpose[m1]\)[\([5]\)]], Re[\(Transpose[m2]\)[\([6]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<m0\>", DisplayFunction \[Rule] Identit]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p6 = ListPlot[Join[Re[\(Transpose[m1]\)[\([6]\)]], Re[\(Transpose[m2]\)[\([7]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<mT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p7 = ListPlot[Join[Re[\(Transpose[m1]\)[\([7]\)]], Re[\(Transpose[m2]\)[\([8]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<L0\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p8 = ListPlot[Join[Re[\(Transpose[m1]\)[\([8]\)]], Re[\(Transpose[m2]\)[\([9]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<LT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p9 = ListPlot[Join[Re[\(Transpose[m1]\)[\([9]\)]], Re[\(Transpose[m2]\)[\([10]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<iT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p10 = ListPlot[Join[Re[\(Transpose[m1]\)[\([10]\)]], Re[\(Transpose[m2]\)[\([11]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<\[Mu]0\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p11 = ListPlot[Join[Re[\(Transpose[m1]\)[\([11]\)]], Re[\(Transpose[m2]\)[\([12]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<iTminusigT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p12 = ListPlot[Join[Re[\(Transpose[m1]\)[\([12]\)]], Re[\(Transpose[m2]\)[\([13]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<T\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p13 = ListPlot[Join[Re[\(Transpose[m1]\)[\([13]\)]], Re[\(Transpose[m2]\)[\([14]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<W\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p14 = ListPlot[Join[Re[\(Transpose[m1]\)[\([14]\)]], Re[\(Transpose[m2]\)[\([15]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<fallinc\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p15 = ListPlot[Join[Re[\(Transpose[m1]\)[\([15]\)]], Re[\(Transpose[m2]\)[\([16]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<jump\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p16 = ListPlot[Join[Re[\(Transpose[m1]\)[\([16]\)]], Re[\(Transpose[m2]\)[\([17]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<h0\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p17 = ListPlot[Join[Re[\(Transpose[m1]\)[\([17]\)]], Re[\(Transpose[m2]\)[\([18]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<hT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p18 = ListPlot[Join[Re[\(Transpose[m1]\)[\([18]\)]], Re[\(Transpose[m2]\)[\([19]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<z0\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p19 = ListPlot[Join[Re[\(Transpose[m1]\)[\([19]\)]], Re[\(Transpose[m2]\)[\([20]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<zT\>", DisplayFunction \[Rule] Identity]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(\(p20 = ListPlot[Join[Re[\(Transpose[m1]\)[\([20]\)]], Re[\(Transpose[m2]\)[\([21]\)]]], PlotJoined\ -> \ True, AxesLabel \[Rule] "\<\[Mu]T\>", DisplayFunction \[Rule] Identit]; \)\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(Show[GraphicsArray[{{p1, p12}, {p13, p14}}]]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(Show[GraphicsArray[{{p1, p2}, {p3, p4}}]]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(Show[GraphicsArray[{{p5, p6}, {p7, p8}}]]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(Show[GraphicsArray[{{p9, p10}, {p11, p12}}]]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(Show[GraphicsArray[{{p14, p15}, {p16, p17}}]]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}], Cell[BoxData[ \(Show[GraphicsArray[{{p18, p19}, {p20, p12}}]]\)], "Input", CellMargins->{{20.8125, -0.1875}, {Inherited, Inherited}}] }, Open ]] }, FrontEndVersion->"Microsoft Windows 3.0", ScreenRectangle->{{0, 800}, {0, 572}}, ScreenStyleEnvironment->"Presentation", PrintingStyleEnvironment->"Printout", ShowPageBreaks->True, WindowToolbars->{"RulerBar", "EditBar"}, WindowSize->{709, 278}, WindowMargins->{{-4, Automatic}, {Automatic, 5}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, PrivateFontOptions->{"FontType"->"Outline"}, Magnification->1.25, StyleDefinitions -> "Report.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[CellGroupData[{ Cell[1731, 51, 127, 1, 66, "Section"], Cell[1861, 54, 369, 5, 92, "Input"], Cell[2233, 61, 396, 7, 172, "Input"], Cell[2632, 70, 1693, 34, 492, "Input"], Cell[4328, 106, 682, 10, 152, "Input"], Cell[5013, 118, 121, 2, 52, "Input"], Cell[5137, 122, 614, 10, 152, "Input"], Cell[5754, 134, 2128, 34, 412, "Input"], Cell[7885, 170, 150, 2, 52, "Input"], Cell[8038, 174, 158, 3, 52, "Input"], Cell[8199, 179, 299, 6, 72, "Input"], Cell[8501, 187, 299, 6, 72, "Input"], Cell[8803, 195, 299, 6, 72, "Input"], Cell[9105, 203, 299, 6, 72, "Input"], Cell[9407, 211, 298, 6, 72, "Input"], Cell[9708, 219, 299, 6, 72, "Input"], Cell[10010, 227, 299, 6, 72, "Input"], Cell[10312, 235, 299, 6, 72, "Input"], Cell[10614, 243, 300, 6, 72, "Input"], Cell[10917, 251, 308, 6, 72, "Input"], Cell[11228, 259, 316, 6, 72, "Input"], Cell[11547, 267, 301, 6, 72, "Input"], Cell[11851, 275, 301, 6, 72, "Input"], Cell[12155, 283, 309, 6, 72, "Input"], Cell[12467, 291, 306, 6, 72, "Input"], Cell[12776, 299, 302, 6, 72, "Input"], Cell[13081, 307, 302, 6, 72, "Input"], Cell[13386, 315, 302, 6, 72, "Input"], Cell[13691, 323, 302, 6, 72, "Input"], Cell[13996, 331, 307, 6, 72, "Input"], Cell[14306, 339, 138, 2, 52, "Input"], Cell[14447, 343, 135, 2, 52, "Input"], Cell[14585, 347, 135, 2, 52, "Input"], Cell[14723, 351, 138, 2, 52, "Input"], Cell[14864, 355, 139, 2, 52, "Input"], Cell[15006, 359, 139, 2, 52, "Input"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)