ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 20 Aug 2013 11:12:35 +0200vector derivative returns a scalarhttps://ask.sagemath.org/question/10456/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
Mon, 19 Aug 2013 12:38:26 +0200https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/Comment by Tomas for <p>Trying to obtain the derivative of $\vec{u} = [-1,1]$ using the following code:</p>
<blockquote>
<p>u = matrix(1,2,[-1, 1])</p>
<p>r = derivative(u,x);
r</p>
</blockquote>
<p>I get a scalar value 0.</p>
<p>Although according the following relation it should be a 2-dimensional zero vector.</p>
<p>$$\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]$$</p>
<p>Why does it happen? In the case it's a bug where could I report it?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17141#post-id-17141Compared 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)]Mon, 19 Aug 2013 12:45:42 +0200https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17141#post-id-17141Answer by ppurka for <p>Trying to obtain the derivative of $\vec{u} = [-1,1]$ using the following code:</p>
<blockquote>
<p>u = matrix(1,2,[-1, 1])</p>
<p>r = derivative(u,x);
r</p>
</blockquote>
<p>I get a scalar value 0.</p>
<p>Although according the following relation it should be a 2-dimensional zero vector.</p>
<p>$$\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]$$</p>
<p>Why does it happen? In the case it's a bug where could I report it?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?answer=15361#post-id-15361Look 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]
Mon, 19 Aug 2013 13:11:45 +0200https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?answer=15361#post-id-15361Comment by ppurka for <p>Look at the help of <code>derivative</code>. It works on symbolic functions, polynomials, and symbolic expressions. Your variable <code>u</code> is not a function, so it is not really being considered a two dimensional symbolic expression or function. If you do</p>
<pre><code>sage: u(x,y) = matrix(1,2,[-1,1])
sage: derivative(u, x)
(x, y) |--> 0
</code></pre>
<p>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 <code>x</code>.</p>
<p>The alternative fix is to work in the symbolic ring:</p>
<pre><code>sage: u = matrix(SR, [-1,1])
sage: derivative(u,x)
[0 0]
</code></pre>
https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17136#post-id-17136This is now ticket 15067Tue, 20 Aug 2013 11:12:35 +0200https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17136#post-id-17136Comment by Tomas for <p>Look at the help of <code>derivative</code>. It works on symbolic functions, polynomials, and symbolic expressions. Your variable <code>u</code> is not a function, so it is not really being considered a two dimensional symbolic expression or function. If you do</p>
<pre><code>sage: u(x,y) = matrix(1,2,[-1,1])
sage: derivative(u, x)
(x, y) |--> 0
</code></pre>
<p>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 <code>x</code>.</p>
<p>The alternative fix is to work in the symbolic ring:</p>
<pre><code>sage: u = matrix(SR, [-1,1])
sage: derivative(u,x)
[0 0]
</code></pre>
https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17138#post-id-17138Thanks, 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.Tue, 20 Aug 2013 06:56:47 +0200https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17138#post-id-17138Comment by Tomas for <p>Look at the help of <code>derivative</code>. It works on symbolic functions, polynomials, and symbolic expressions. Your variable <code>u</code> is not a function, so it is not really being considered a two dimensional symbolic expression or function. If you do</p>
<pre><code>sage: u(x,y) = matrix(1,2,[-1,1])
sage: derivative(u, x)
(x, y) |--> 0
</code></pre>
<p>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 <code>x</code>.</p>
<p>The alternative fix is to work in the symbolic ring:</p>
<pre><code>sage: u = matrix(SR, [-1,1])
sage: derivative(u,x)
[0 0]
</code></pre>
https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17137#post-id-17137Anyway, 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?Tue, 20 Aug 2013 07:06:15 +0200https://ask.sagemath.org/question/10456/vector-derivative-returns-a-scalar/?comment=17137#post-id-17137