Ask Your Question
0

vector derivative returns a scalar

asked 2013-08-19 12:38:26 +0100

Tomas gravatar image

updated 2013-08-19 12:39:00 +0100

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 flag offensive close merge delete

Comments

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[0](a)(x) x |--> D[0](b)(x)]

Tomas gravatar imageTomas ( 2013-08-19 12:45:42 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-08-19 13:11:45 +0100

ppurka gravatar image

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]
edit flag offensive delete link more

Comments

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.

Tomas gravatar imageTomas ( 2013-08-20 06:56:47 +0100 )edit

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?

Tomas gravatar imageTomas ( 2013-08-20 07:06:15 +0100 )edit

This is now ticket 15067

ppurka gravatar imageppurka ( 2013-08-20 11:12:35 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-08-19 12:38:26 +0100

Seen: 1,510 times

Last updated: Aug 19 '13