# vector derivative returns a scalar

Trying to obtain the derivative of $\vec{u} = [-1,1]$ using the following code:

u = matrix(1,2,[-1, 1])

r = derivative(u,x); r

I get a scalar value 0.

Although according the following relation it should be a 2-dimensional zero vector.

$$\frac{\mathrm{d} \vec{u}}{\mathrm{d} x} =\frac{\mathrm{d}}{\mathrm{d} x} [-1, 1] = [ \frac{\mathrm{d}}{\mathrm{d} x}(-1), \frac{\mathrm{d}}{\mathrm{d} x}(1) ] = [0, 0]$$

Why does it happen? In the case it's a bug where could I report it?

Thanks

edit retag close merge delete

Compared to: a(x) = function('a',x) b(x) = function('b',x) u = matrix(1,2,[a,b]) r = derivative(u,x);r Which gives a vector as expected: [x |--> D(a)(x) x |--> D(b)(x)]

Sort by » oldest newest most voted

Look at the help of derivative. It works on symbolic functions, polynomials, and symbolic expressions. Your variable u is not a function, so it is not really being considered a two dimensional symbolic expression or function. If you do

sage: u(x,y) = matrix(1,2,[-1,1])
sage: derivative(u, x)
(x, y) |--> 0


then you can see that it is considering it as a two dimensional function. In the second case, you have a function of one variable in the variable x.

The alternative fix is to work in the symbolic ring:

sage: u = matrix(SR, [-1,1])
sage: derivative(u,x)
[0 0]

more

Thanks, the fix with a symbolic ring is helpful. In my problem the $\vec{u}$ really is a function, just happens to be a constant at this occasion.

Anyway, I reckon that the first example is probably a bug. The derivative of n-dimensional vector should have n-dimensions again no matter to which ring it belongs to. Would you know how to report that, please?