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, 02 Oct 2012 23:58:31 +0200functions with vector inputshttps://ask.sagemath.org/question/9375/functions-with-vector-inputs/Are vector functions supported in sage?
as in:
f1(r,phi,theta) = 1/r
f2(r,phi,theta) = 1
f3(r,phi,theta) = 1
F = vector([f1, f2, f3])
G=rot(F) # vector function
An ancient [post](http://www.mail-archive.com/sage-devel@googlegroups.com/msg31402.html) seems to suggest that rot has to be defined with a positional python-argument like rot(*F).
Is there a way for "rot" to take the vector symbolically as an argument?
Mon, 01 Oct 2012 15:48:52 +0200https://ask.sagemath.org/question/9375/functions-with-vector-inputs/Comment by kcrisman for <p>Are vector functions supported in sage?</p>
<p>as in:</p>
<pre><code>f1(r,phi,theta) = 1/r
f2(r,phi,theta) = 1
f3(r,phi,theta) = 1
F = vector([f1, f2, f3])
G=rot(F) # vector function
</code></pre>
<p>An ancient <a href="http://www.mail-archive.com/sage-devel@googlegroups.com/msg31402.html">post</a> seems to suggest that rot has to be defined with a positional python-argument like rot(*F).</p>
<p>Is there a way for "rot" to take the vector symbolically as an argument?</p>
https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?comment=18940#post-id-18940I think I know what you mean now. `sage: rot(r,phi,theta) = F` could in theory make a vector function, but it doesn't currently know what to do.Mon, 01 Oct 2012 20:02:19 +0200https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?comment=18940#post-id-18940Answer by kcrisman for <p>Are vector functions supported in sage?</p>
<p>as in:</p>
<pre><code>f1(r,phi,theta) = 1/r
f2(r,phi,theta) = 1
f3(r,phi,theta) = 1
F = vector([f1, f2, f3])
G=rot(F) # vector function
</code></pre>
<p>An ancient <a href="http://www.mail-archive.com/sage-devel@googlegroups.com/msg31402.html">post</a> seems to suggest that rot has to be defined with a positional python-argument like rot(*F).</p>
<p>Is there a way for "rot" to take the vector symbolically as an argument?</p>
https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?answer=14090#post-id-14090I usually think of a gradient as being a property of a single-variable function... but anyway, is this what you want?
sage: F.diff()
[(r, phi, theta) |--> -1/r^2 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
sage: diff(F)
[(r, phi, theta) |--> -1/r^2 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
Mon, 01 Oct 2012 16:16:46 +0200https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?answer=14090#post-id-14090Comment by mirk for <p>I usually think of a gradient as being a property of a single-variable function... but anyway, is this what you want?</p>
<pre><code>sage: F.diff()
[(r, phi, theta) |--> -1/r^2 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
sage: diff(F)
[(r, phi, theta) |--> -1/r^2 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
[ (r, phi, theta) |--> 0 (r, phi, theta) |--> 0 (r, phi, theta) |--> 0]
</code></pre>
https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?comment=18943#post-id-18943My mistake: the problem arises while calculating the divergence. It was a copy/paste failure. I will edit the question. I don't think this is the answer I was looking for.Mon, 01 Oct 2012 17:39:11 +0200https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?comment=18943#post-id-18943Answer by benjaminfjones for <p>Are vector functions supported in sage?</p>
<p>as in:</p>
<pre><code>f1(r,phi,theta) = 1/r
f2(r,phi,theta) = 1
f3(r,phi,theta) = 1
F = vector([f1, f2, f3])
G=rot(F) # vector function
</code></pre>
<p>An ancient <a href="http://www.mail-archive.com/sage-devel@googlegroups.com/msg31402.html">post</a> seems to suggest that rot has to be defined with a positional python-argument like rot(*F).</p>
<p>Is there a way for "rot" to take the vector symbolically as an argument?</p>
https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?answer=14099#post-id-14099I don't understand the question. Are you asking if it's possible to use the special notation like `f(x) = x^2` for the creation of vector valued functions? If so, the answer is currently **no**, but it could probably be added to the Sage preparser without much problem. Of course you can always define the function `rot` the ordinary way to take a vector and return a vector:
sage: rot = lambda v: vector([1/v[0],1,1])
sage: rot(vector([2,1,1]))
(1/2, 1, 1)Tue, 02 Oct 2012 23:58:31 +0200https://ask.sagemath.org/question/9375/functions-with-vector-inputs/?answer=14099#post-id-14099