Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
2

functions of variables with matrices

asked 8 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

mforets gravatar image

updated 8 years ago

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'.

Preview: (hide)
link

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 ( 8 years ago )

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 ( 8 years ago )

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: 8 years ago

Seen: 997 times

Last updated: Oct 10 '16