(*^ ::[ frontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.1"; macintoshStandardFontEncoding; paletteColors = 128; automaticGrouping; currentKernel; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; ; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; ; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; ; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; ; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; ; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; ; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; ; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-5, 12, "Courier"; ; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R65535, L-5, 12, "Courier"; ; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B65535, L-5, 12, "Courier"; ; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; ; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Geneva"; ; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = leftheader, inactive, L2, 12, "Times"; ; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; ; fontset = leftfooter, inactive, L2, 12, "Times"; ; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; ; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; ; ] :[font = special1; inactive; preserveAspect; ] Visualizing Differential Equations The cell below defines a Mathematica procedure SlopeField that draws slope fields for a differential equation of the form y' = f(x, y) Evaluate it now. ;[s] 10:0,1;70,0;97,2;108,0;122,1;132,0;260,1;272,0;274,3;289,0;291,-1; 4:5,13,9,Times,0,12,0,0,0;3,13,9,Times,1,12,0,0,0;1,13,9,Times,2,12,0,0,0;1,13,9,Times,1,12,65535,0,0; :[font = input; preserveAspect; ] SlopeField[foo_, xlow_, xhigh_, ylow_, yhigh_] := Block[{slopes = {}, hx = (xhigh - xlow)/20.0, hy = (yhigh - ylow)/20.0, dx = (xhigh - xlow)/8.0, dy = (yhigh - ylow)/8.0, x, y, i, j, m }, For[x = xlow; i = 0, i <= 8, ++i; x = x + dx, For[y = ylow; j = 0, j <= 8, ++j; y = y + dy, m = foo[x, y]; If[Abs[m * hx] <= hy, kx = hx, kx = hy/Abs[m]]; slopes = Join[{Point[{x, y}]}, slopes]; If[NumberQ[m], slopes = Join[{Line[{{x-kx, y-m*kx}, {x+kx, y+m*kx}}]}, slopes]] ] ]; Show[Graphics[{PointSize[0.01], slopes}], Axes -> Automatic, AspectRatio -> 1.0, DisplayFunction -> $DisplayFunction] ] :[font = special1; inactive; dontPreserveAspect; ] The following cell shows how SlopeField can graph a slope field like the ones in the browser window. Evaluate it now. When you evaluate this cell it will generate warning messages because the right hand side of this differential equation is undefined when x = 0. ;[s] 9:0,0;29,1;30,2;41,1;42,0;104,3;119,0;122,3;265,0;267,-1; 4:4,13,9,Times,0,12,0,0,0;2,13,9,Times,2,12,0,0,0;1,13,9,Times,1,12,0,0,0;2,13,9,Times,1,12,65535,0,0; :[font = input; preserveAspect; ] Clear[fcn] fcn[x_, y_] := y/x SlopeField[fcn, -3, 3, -3, 3] :[font = special1; inactive; dontPreserveAspect; ] Notice that the function f[x, y] on the right hand side of the differential equation dy/dx = f[x, y] must be specified in a line of its own rather than as part of the SlopeField line. In other words, WRONG! SlopeField[-x/y, -1.0, 1.0, -1.0, 1.0] WRONG! will not work. In addition, the first variable must be the independent variable and the second variable must be the dependent variable. For example, the differential equation dp/dt = p(1 - p) should be entered as fcn[t_, p_] := p(1 - p) NOT fcn[p_, t_] := p(1 - p) The form of the SlopeField statement is SlopeField[function, xlow, xhigh, ylow, yhigh] where xlow and xhigh give the range for the variable x, and ylow and yhigh give the range for the variable y. ;[s] 36:0,0;26,1;33,0;111,1;126,0;195,1;205,0;243,3;302,0;364,1;375,0;421,1;430,0;528,1;544,0;585,1;608,0;612,1;642,2;643,0;661,1;671,0;687,1;733,0;742,1;746,0;753,1;758,0;792,1;793,0;800,1;804,0;811,1;816,0;850,1;851,0;853,-1; 4:18,13,9,Times,0,12,0,0,0;16,13,9,Times,1,12,0,0,0;1,13,9,Times,0,12,65535,0,0;1,13,9,Times,1,12,65535,0,65535; ^*)