vitavictoriya
(Viktoriya Martynyuk-Lototska)
1
Hi! I draw graphic using function
gr1[f_, xmin_, xmax_, slices_] :=
Module[{span = (xmax - xmin)/slices, ext},
ext[op_, r_] := First@Quiet@op[{f, r <= x <= r + span}, x];
Plot[f, {x, xmin, xmax},
Prolog → {FaceForm, EdgeForm,
Rectangle @@@ ({{#, ext[Minimize, #]}, {# + span,
ext[Maximize, #]}} & /@ Most@Range[xmin, xmax, span])}]];
f := x + 3*Sin[x + 2];
gr1[f, -5, -3, 10]
then I want loop this drawing ,for example a=-5,b=-3,eps=0.1
While[abs(b-a)>eps,gr1[f, a, b, 10]; a=(a+b)/2+0,5,b=(a+b)/2+0,5)]
but when I run this code it doesn’t work, please help)
sukrause
(Udo Krause)
2
If you enter the x’es to the places where they are needed,
Clear[gr1]
gr1[f_, xmin_, xmax_, slices_] :=
Module[{span = (xmax - xmin)/slices, ext, x},
ext[op_, r_] := First@Quiet@op[{f[x], r <= x <= r + span}, x];
Plot[f[x], {x, xmin, xmax},
Prolog -> {FaceForm, EdgeForm,
Rectangle @@@ ({{#, ext[Minimize, #]}, {# + span,
ext[Maximize, #]}} & /@ Most@Range[xmin, xmax, span])}]]
you get a picture throwing an error message “EdgeForm is not a Graphics primitve or directive”
sukrause
(Udo Krause)
4
Well, fixed; Even if you initalize eps, a, and b and use function name Abs[], it does not plot (see evaluation of While[])
With[{eps = 0.1},
a = 10; b = 20;
While[Abs[b - a] > eps,
gr1[f, a, b, 10];
a = (a + b)/2 - 1;
b = (a + b)/2 + 1]
]
so, you manage to see the array of graphics this way
gr1[f, Sequence @@ #, 10]& /@ FixedPointList[{(#[[1]] + #[[2]])/2 - 1, (#[[1]] + #[[2]])/2 + 1} &, {10, 20}]