Ask Your Question
0

Extracting a matrix from linear expressions

asked 2013-02-11 20:06:29 -0600

Pascal Ortiz gravatar image

updated 2013-02-11 20:07:12 -0600

Suppose I have a vector depending on symbolic parameters, say v=vector([a-b, b-c, c-a]). How to extract the matrix naturally associated with the vector v ? I mean the matrix M

1 -1 0
0 1 -1
1 0 -1

since vector([a, b, c]) * M == v. In fact I need the equivalent to the Maple command GenerateMatrix.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
2

answered 2013-02-11 23:17:18 -0600

achrzesz gravatar image
maxima('coefmatrix([a-b,b-c,c-a],[a,b,c])').sage()      
[ 1 -1  0]
[ 0  1 -1]
[-1  0  1]
edit flag offensive delete link more
0

answered 2013-02-12 00:21:34 -0600

DSM gravatar image

updated 2013-02-12 00:27:46 -0600

Alternatively, you can use the Matrix constructor:

sage: s = var("a b c")
sage: v = vector([a-b, b-c, c-a])
sage: Matrix(QQ, [v.derivative(x) for x in (a,b,c)]).T
[ 1 -1  0]
[ 0  1 -1]
[-1  0  1]
sage: Matrix(ZZ, 3, lambda i, j: v[i].coeff(s[j]))
[ 1 -1  0]
[ 0  1 -1]
[-1  0  1]

etc., depending on your v. I can't seem to find a Sage-side function which'll just do it.

edit flag offensive delete link more

Comments

So should we add one?

kcrisman gravatar imagekcrisman ( 2013-02-12 04:16:05 -0600 )edit
1

I don't think we should add one *unless* somewhere *Linear Expressions* are defined as an object in Sage. This makes sense only for linear expressions.

ppurka gravatar imageppurka ( 2013-02-13 14:28:13 -0600 )edit
0

answered 2013-02-13 14:32:49 -0600

ppurka gravatar image

updated 2013-02-13 14:34:56 -0600

By the way, you can do this in one go by defining a symbolic function.

sage: f(a,b,c) = [a-b, b-c, c-a]
sage: f.derivative()
[ (a, b, c) |--> 1 (a, b, c) |--> -1  (a, b, c) |--> 0]
[ (a, b, c) |--> 0  (a, b, c) |--> 1 (a, b, c) |--> -1]
[(a, b, c) |--> -1  (a, b, c) |--> 0  (a, b, c) |--> 1]
sage: f.derivative()(a,b,c)
[ 1 -1  0]
[ 0  1 -1]
[-1  0  1]
sage: type(_)
<type 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'>

If you started out with a vector in your computations then you can get a list by doing this

sage: a,b,c = var('a,b,c')
sage: v = vector([a-b, b-c, c-a])
sage: f(a,b,c) = v.list()
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

Stats

Asked: 2013-02-11 20:06:29 -0600

Seen: 194 times

Last updated: Feb 13 '13