Ask Your Question

how to create a matrix valued function?

asked 2017-11-16 15:49:53 +0200

flawr gravatar image

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 flag offensive close merge delete


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)
mforets gravatar imagemforets ( 2017-11-16 22:31:40 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-16 20:30:41 +0200

Ant gravatar image

Like this?

def g(x,y):
    return matrix(SR,2,2,[1,x,cos(y),x*y])
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2017-11-16 15:47:47 +0200

Seen: 822 times

Last updated: Nov 16 '17