Ask Your Question
2

functions of variables with matrices

asked 2016-10-10 03:19:04 +0100

rtc gravatar image

I am trying to make a function of a variable with sage for example:

f(x) = sin(x)
f(x+y)

yields:

sin(x+y)

However if It is in a matrix this no longer works:

f(x) = matrix([[sin(x)],[cos(x)]])
f(x+y)

yields:

sin(x)
cos(x)

Is this not possible or am I missing something to make this work?

I am using sage 7.3 on Ubuntu 16.04 with the aims ppa.

edit retag flag offensive close merge delete

1 Answer

Sort by Β» oldest newest most voted
1

answered 2016-10-10 21:10:55 +0100

mforets gravatar image

updated 2016-10-10 21:18:44 +0100

If you ask for the type of $f$, you get <πšπš’πš™πšŽ'𝚜𝚊𝚐𝚎.πšœπš’πš–πš‹πš˜πš•πš’πšŒ.πšŽπš‘πš™πš›πšŽπšœπšœπš’πš˜πš—.π™΄πš‘πš™πš›πšŽπšœπšœπš’πš˜πš—'>: apparently the substitution into symbolic expressions is not overloaded to matrix-valued functions. However, with

var('x y')
f = matrix(SR, [[sin(x)],[cos(x)]])
type(f)

you get <πšπš’πš™πšŽ'𝚜𝚊𝚐𝚎.πš–πšŠπšπš›πš’πš‘.πš–πšŠπšπš›πš’πš‘βŽ―πšœπš’πš–πš‹πš˜πš•πš’πšŒβŽ―πšπšŽπš—πšœπšŽ.π™ΌπšŠπšπš›πš’πš‘βŽ―πšœπš’πš–πš‹πš˜πš•πš’πšŒβŽ―πšπšŽπš—πšœπšŽ'>, and

f(x=x+y)

gives the expected result.

Alternatively, try with:

def f(x): return matrix(SR, [[sin(x)],[cos(x)]])

to obtain an object $f$ of type 'function'.

edit flag offensive delete link more

Comments

Thanks that answers my question. Is the substitution not being overloaded to matrix valued functions a bug? or a feature that hasn't been implemented? or something that is done on purpose?

rtc gravatar imagertc ( 2016-10-10 23:44:54 +0100 )edit

i think this is a feature that hasn't been implemented. for the moment, i can just point you to the discussion here #12075.

mforets gravatar imagemforets ( 2017-04-09 11:39:46 +0100 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2016-10-10 03:19:04 +0100

Seen: 873 times

Last updated: Oct 10 '16