(* Stability of ODE's and methods *) (* An ODE is said to be stable over a certain interval if two solutions starting out close to each other remain close over the entire interval *) (* For example, the one below is stable if a < 0, and unstable if a > 0 *) (* To explore unstable case. set a=1. Set x[0] = 1 or 1.1. For the stable case set a = -1, and try x[0] = 1 and 11 *) a = 1 solutionA = NDSolve[{x'[t] == a*x[t], x[0] == 1.0}, x, {t, 0, 10}] plotA = Plot[Evaluate[x[t] /. solutionA ], {t, 0, 10}, PlotStyle->{Hue[1], Thickness[0.01]}, PlotLabel -> FontForm["x(0)= 1.0", {"Courier", 15}], AxesLabel -> {t , x[t]}] solutionB = NDSolve[{x'[t] == a*x[t], x[0] == 1.1}, x, {t, 0, 10}] plotB = Plot[Evaluate[x[t] /. solutionB ], {t, 0, 10}, PlotStyle->{Hue[0.5], Thickness[0.01]}, PlotLabel -> FontForm["x(0) = 1.1", {"Courier", 15}], AxesLabel -> {t, x[t]}] (* Print the difference between the solutions at t = 10 *) Print[] Print["Difference between solutions at t=10 ", Evaluate[x[10] /. solutionB ] - Evaluate[x[10] /. solutionA ] ] Print[] Plot[Evaluate[x[t] /. solutionB ] - Evaluate[x[t] /. solutionA ], {t, 0, 10}, PlotLabel -> FontForm["Difference", {"Courier", 15}], AxesLabel -> {t, x[t]}] Clear[a]