Ask Your Question
1

how to create a matrix valued function?

asked 2017-11-16 08:49:53 -0600

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

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

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-16 13:30:41 -0600

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

Stats

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

Seen: 29 times

Last updated: Nov 16