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.Sat, 01 Sep 2018 19:33:34 +0200vector constants and vector functionshttps://ask.sagemath.org/question/43550/vector-constants-and-vector-functions/I'm using sage (through cocalc) with my multivariable calculus class this year. I'm looking for a consistent way to define symbol vector-valued functions and vector constants.
I can define a symbolic vector-valued function like this:
var('t')
r(t) = [1, t]
r(1) + r(2) # works as expected
I can define constant vectors like this:
a = vector([1, 1])
b = vector([10, 20])
c = a + b # works as expected
But `vector` does not work for symbolic functions: `r(t)=vector([1, t])` throws.
So:
- `vector` seems **required** for constants, else we don't get correct algebraic behavior
- `vector` **cannot** be used with symbolic functions, else sage throws
**Question**: I'm worried this is going to cause a lot of confusion for my students. Is there a consistent way to define vectors for both constant values and symbolic expressions? Sat, 01 Sep 2018 18:08:04 +0200https://ask.sagemath.org/question/43550/vector-constants-and-vector-functions/Answer by rburing for <p>I'm using sage (through cocalc) with my multivariable calculus class this year. I'm looking for a consistent way to define symbol vector-valued functions and vector constants.</p>
<p>I can define a symbolic vector-valued function like this:</p>
<pre><code>var('t')
r(t) = [1, t]
r(1) + r(2) # works as expected
</code></pre>
<p>I can define constant vectors like this:</p>
<pre><code>a = vector([1, 1])
b = vector([10, 20])
c = a + b # works as expected
</code></pre>
<p>But <code>vector</code> does not work for symbolic functions: <code>r(t)=vector([1, t])</code> throws.</p>
<p>So:</p>
<ul>
<li><code>vector</code> seems <strong>required</strong> for constants, else we don't get correct algebraic behavior</li>
<li><code>vector</code> <strong>cannot</strong> be used with symbolic functions, else sage throws</li>
</ul>
<p><strong>Question</strong>: I'm worried this is going to cause a lot of confusion for my students. Is there a consistent way to define vectors for both constant values and symbolic expressions? </p>
https://ask.sagemath.org/question/43550/vector-constants-and-vector-functions/?answer=43551#post-id-43551One approach is to use symbolic expressions *instead* of functions, e.g.
var('t')
r = vector([1, t])
The addition example becomes slightly verbose (but certainly unambiguous):
r(t=1) + r(t=2)
An apparent downside is that this blurs the line between variables and symbolic constants which might also appear:
var('t,c')
s = vector([1, c*t])
However, many operations which are really operations on functions are implemented in Sage as operations on symbolic expressions, where the dependent variables are passed alongside the symbolic expression.
For example, to calculate the Jacobian:
sage: jacobian(s, [t])
[0]
[c]Sat, 01 Sep 2018 19:33:34 +0200https://ask.sagemath.org/question/43550/vector-constants-and-vector-functions/?answer=43551#post-id-43551