Ask Your Question

# 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]])

edit retag close merge delete

## Comments

actually 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)
6


## 1 answer

Sort by » oldest newest most voted

Like this?

def g(x,y):
return matrix(SR,2,2,[1,x,cos(y),x*y])

more

## Your Answer

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

Add Answer

## Stats

Asked: 2017-11-16 08:47:47 -0500

Seen: 136 times

Last updated: Nov 16 '17