ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 01 May 2012 07:22:55 +0200A 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 07:22:55 +0200https://ask.sagemath.org/question/8942/