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.Thu, 16 Nov 2017 22:31:40 +0100how to create a matrix valued function?https://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/I'm trying to define a function g that takes two values and maps tem to a 2x2 matrix. What I've tried is
x,y = var('x,y');
g(x,y) = matrix(SR,2,2,[1,x,cos(y),x*y]);
but if I try to evaluate this function, the variables in the matrix are not evaluated:
sage: g(0,0)
[ 1 x]
[cos(y) x*y]
I expect the output to be
[ 1 0]
[ 1 0]
I also tried other variants bud did not succeed, e.g.
g(x,y) = matrix([[1,x],[x,y]])Thu, 16 Nov 2017 15:47:47 +0100https://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/Comment by mforets for <p>I'm trying to define a function g that takes two values and maps tem to a 2x2 matrix. What I've tried is</p>
<pre><code>x,y = var('x,y');
g(x,y) = matrix(SR,2,2,[1,x,cos(y),x*y]);
</code></pre>
<p>but if I try to evaluate this function, the variables in the matrix are not evaluated:</p>
<pre><code>sage: g(0,0)
[ 1 x]
[cos(y) x*y]
</code></pre>
<p>I expect the output to be</p>
<pre><code>[ 1 0]
[ 1 0]
</code></pre>
<p>I also tried other variants bud did not succeed, e.g.</p>
<pre><code> g(x,y) = matrix([[1,x],[x,y]])
</code></pre>
https://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/?comment=39616#post-id-39616actually i also expect that evaluating the symbolic matrix should be available (which currently isn't, as you've shown), in the same way that it works for scalar functions,
sage: f(x, y, z) = x+y+z
sage: f(1,2,3)
6Thu, 16 Nov 2017 22:31:40 +0100https://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/?comment=39616#post-id-39616Answer by Ant for <p>I'm trying to define a function g that takes two values and maps tem to a 2x2 matrix. What I've tried is</p>
<pre><code>x,y = var('x,y');
g(x,y) = matrix(SR,2,2,[1,x,cos(y),x*y]);
</code></pre>
<p>but if I try to evaluate this function, the variables in the matrix are not evaluated:</p>
<pre><code>sage: g(0,0)
[ 1 x]
[cos(y) x*y]
</code></pre>
<p>I expect the output to be</p>
<pre><code>[ 1 0]
[ 1 0]
</code></pre>
<p>I also tried other variants bud did not succeed, e.g.</p>
<pre><code> g(x,y) = matrix([[1,x],[x,y]])
</code></pre>
https://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/?answer=39611#post-id-39611Like this?
def g(x,y):
return matrix(SR,2,2,[1,x,cos(y),x*y])
Thu, 16 Nov 2017 20:30:41 +0100https://ask.sagemath.org/question/39606/how-to-create-a-matrix-valued-function/?answer=39611#post-id-39611