# problem with drawing in a loop

Posted 9 years ago
2052 Views
|
3 Replies
|
0 Total Likes
|
 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_] := 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)
3 Replies
Sort By:
Posted 9 years ago
 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 waygr1[f, Sequence @@ #, 10]& /@ FixedPointList[{(#[[1]] + #[[2]])/2 - 1, (#[[1]] + #[[2]])/2 + 1} &, {10, 20}]
Posted 9 years ago
 try this Attachments:
Posted 9 years ago
 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"