(* finding local minima for a function of one variable *) (* To run on command line: math -run "< Newton, AccuracyGoal -> 5, MaxIterations -> 4 ] *) Print[" "] Print["-NOW USE MATHEMATICA's Newton's "] Print["---which has a few safety guards built in. ------- " ] Print[ " "] answer = FindMinimum [F[x], {x}, Method -> Newton ] FindMinimumPlot [F[x], {{x, x0}}, Method -> Newton ] xmin = x /. answer[ [2] ] ymin = answer[ [1] ] Print[" "] Print["Value of X that minimizes F, xmin = ", xmin] Print[" "] Print[" F(xmin)= ", ymin] Print[" "] gr1 = Plot[F[x], {x, -2, 2}]; gr2 = Plot[ 100*(x - xmin), {x, xmin - 0.01, xmin + 0.01}]; Show[gr1,gr2] Clear[y,x0,x1,x2,d1,d2]