ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 27 May 2015 09:59:07 -0500Symbolic Linear Algebrahttps://ask.sagemath.org/question/26952/symbolic-linear-algebra/I'd like to manipulate symbolic expression in linear algebra. More specifically, suppose that A,B, etc. are matrices and v,w,.. etc are column vectors. I have various expressions in them that I'd like expanded and grouped. It also should know about transpose (that it's an involution). For example, if I write the expression:
transpose(v-w)*A*(v-w). It should be able to expand this to
transpose(v)*A*v - transpose(v)*A*w - transpose(w)*A*v + transpose(w)*A*w
Also, I'd like to specify that A is symmetric -- A == transpose(A). In that case the above would simplify to
transpose(v)*A*v - 2*transpose(v)*A*w + transpose(w)*A*w
if we idenfity a 1 by 1 matrix with a scalar. It would also be nice, if we could specify symbolic scalars, and, for example to say that A in hom(V,W), where V,W are some vector spaces. In that case if we try to multiply things that are incompatible we would get an error. This looks like it should be part of some sort of universal algebra package. Does such a thing exist in SAGE?VictorWed, 27 May 2015 09:59:07 -0500https://ask.sagemath.org/question/26952/A question on symbolic Matrices - unexpected Decimals in algebraic entryhttps://ask.sagemath.org/question/8942/a-question-on-symbolic-matrices-unexpected-decimals-in-algebraic-entry/Firstly, I'd just like to say that I am starting out with Sage adn Python at the moment, really impressed by the power of Sage and its potential! I am coming at this from an engineering and C++ background, and am currently trying to look at an engineering problem using some matrix linear algebra. I am setting up a from of stiffness matrix and am trying to extract the symbolic eigenvalues and eigenvectors from this. The stiffness matrix below is generated through a few different matrix multiplication operations, based on node and connectivity matrices. Despite trying to define these as being "SR" rings, I seem to end up with entries like (b + 1.0g + 1.0s) rather than the (b + g + s) I was expecting. I suspect this is due to me not understanding rings properly and how to apply them. I have tried the explanations in the Sage documentation, can anybody recommend some further reading or tutorials on this, because it does seem to be a vital topic in getting to grips with Sage?
I enclose my code below, in case anybody can spot a glaringly stupid thing that I've done...
many thanks,
Brian
N = matrix(QQ,[[1,0,-1,0],[0,1,0,-1]])
C = matrix(QQ,[[-1,0,1,0],[0,-1,0,1],[-1,1,0,0],[0,-1,1,0],[0,0,-1,1],[1,0,0,-1]])
D = C.transpose()
space = N.nrows()
M = N*D
M
II = identity_matrix(QQ,space)
b,s,g = var('b s g')
numMembers = M.ncols()
LVector = II
#loop through members to create LVector
for i in range(numMembers):
m1 = M.matrix_from_columns([i])
mt = m1.transpose()
mag = m1.norm()
Coeff = m1*mt/(mag^2)
size = m1.norm()
if i<2:
#for bars
L = -g*(II - Coeff) + b*Coeff
else:
L = g*(II - Coeff) + s*Coeff
L.factor()
if i == 0:
LVector = L
else:
LVector = LVector.block_sum(L)
print L.str()
print LVector.str()
Pre = D.tensor_product(II)
Post = C.tensor_product(II)
K = Pre*LVector
K = K*Post
Ks = K.change_ring(SR)
print Ks.str()
Eigen = K.eigenvectors_left()
print Eigen.str()BrianLoudonTue, 01 May 2012 00:22:55 -0500https://ask.sagemath.org/question/8942/