Student Support Forum: 'so slowly' topicStudent Support Forum > General > Archives > "so slowly"

 Next Comment > Help | Reply To Topic
 Author Comment/Response AnopT 03/24/09 02:34am Hello. I have a code of golden section method. Why it is performed so slowly (more than 10 minutes)? f[x_] := x^2 - Sin[x]*Cos[x]; (*заданные значения*) dx0 = 0.1; dy0 = 0.01; a0 = -10; b0 = 100; g = GoldenRatio - 1; i = 0; (*реализация алгоритма*) GoldSearch[f0_, a0_, b0_, dx0_, dy0_] := Module[{a = a0, b = b0, dx = dx0, dy = dy0}, While[dx >= dx0, l1 = g*(Abs[a] + Abs[b]); x1 = l1; x2 = (Abs[a] + Abs[b])/2 - l1; If[f[x1] > f[x2], {a = x1, b = x2}]; If[f[x1] < f[x2], {a = x2, b = x1}]; Print[N[a] " ", N[f[x1]], " ", N[b], " ", N[f[x2]]]; dx = Abs[a] + Abs[b]; i++; (*Print[N[x1]," ",N[x2]];*) ]; {N[a], N[f[(a + b)/2]]}]; GoldSearch[f[x], a0, b0, 0.1, 1] min = FindMinimum[f[x], {x, 5}]; Print["Минимум функции ", f[x], " лежит в точке ", min]; Plot[f[x], {x, -50, 50}] URL: ,

 Subject (listing for 'so slowly') Author Date Posted so slowly AnopT 03/24/09 02:34am Re: so slowly yehuda ben-s... 03/29/09 11:38am
 Next Comment > Help | Reply To Topic