3
$\begingroup$

Bug introduced in 7.0 and fixed in 9.0


I want to use the built-in BernsteinBasis[] to learn about Bezier curves. I tried the following code:

Plot[Evaluate @ Table[D[BernsteinBasis[3, k, u], u], {k, 0, 3}], {u, 0, 1}]

enter image description here

I tried many workrounds. Finally, I added PiecewiseExpand[] before BernsteinBasis[], then it works well.

Plot[Evaluate @ 
     Table[D[PiecewiseExpand @ BernsteinBasis[3, k, u], u], 
           {k, 0, 3}], {u, 0, 1}]

enter image description here


Bug fixed

enter image description here enter image description here

$\endgroup$
8
  • $\begingroup$ Evaluated->True does the trick. You may search this site about it. Plot[Table[D[BernsteinBasis[3, k, u], u], {k, 0, 3}], {u, 0, 1}, Evaluated -> True] $\endgroup$ Sep 29, 2014 at 3:41
  • $\begingroup$ @belisarius, In V8,Plot[Table[D[BernsteinBasis[3, k, u], u], {k, 0, 3}], {u, 0, 1}, Evaluated -> True] cannot give the result as OP shown. $\endgroup$
    – user8336
    Sep 29, 2014 at 5:20
  • 1
    $\begingroup$ This is version/system dependent. In v10.0.1 on a Mac, original input works fine without Evaluated -> True or PiecewiseExpand. $\endgroup$
    – Bob Hanlon
    Sep 29, 2014 at 5:34
  • 2
    $\begingroup$ I have no answer to this, but I wanted to comment that out of the corner of my eye I thought the question was "Why can't the Berenstain Bears work normally", which you must admit is pretty intriguing. $\endgroup$ Apr 15, 2016 at 16:15
  • 1
    $\begingroup$ I'm sorry, you've misspelt Berenstain. $\endgroup$
    – user484
    Apr 16, 2016 at 2:33

1 Answer 1

3
$\begingroup$

The problem in V8.0.4 is that

D[BernsteinBasis[3, 0, u], u]

evaluates as

3 (BernsteinBasis[2, -1, u] - BernsteinBasis[2, 0, u])

A negative second argument is disallowed. The problem (i.e., bug) is that the general rule

D[BernsteinBasis[3, k, u], u]
(* 3 (BernsteinBasis[2, -1 + k, u] - BernsteinBasis[2, k, u]) *)

is applied when it is incorrect (e.g., for k == 0 and k == 3).

This is fixed in V9 and V10.

It is interesting, if inexplicable, that it is accounted for when applying PiecewiseExpand to the result of the differentiation in V8.0.4:

PiecewiseExpand@D[BernsteinBasis[3, k, u], u]

Mathematica graphics

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.