On 7/27/07, Roger Mason <[EMAIL PROTECTED]> wrote: > I'm still trying to do some linear algebra with sage. > > sage: var('x1,y1,z1, x2,y2,z2, x3,y3,z3') > (x1, y1, z1, x2, y2, z2, x3, y3, z3) > sage: var('p1,p2,p3') > (p1, p2, p3) > sage: var('x,y,z') > (x, y, z) > sage: var('alpha, beta') > (alpha, beta) > sage: p1 = transpose(matrix([[x1,y1,z1]])) > sage: p1 > > [x1] > [y1] > [z1] > sage: p2 = transpose(matrix([[x2,y2,z2]])) > sage: p3 = transpose(matrix([[x3,y3,z3]])) > sage: alpha = p2 - p1 > sage: alpha > > [x2 - x1] > [y2 - y1] > [z2 - z1] > sage: beta = p3 - p1 > sage: beta > > [x3 - x1] > [y3 - y1] > [z3 - z1] > sage: alpha[0] > ( x2 - x1) > > At this point I wnat to make a matrix that looks like this: > > x y z > alpha[0] alpha[1] alpha[2] > beta[0] beta[1] beta[2] > > My efforts always end in an error.
alpha[0] is the first row of alpha, so you probably want alpha[0][0]. I should warn you that working with symbolic matrices like you're doing is potentially very slow, since so far no work has gone into making it fast. In contrast, if you work with matrices over a multivariate polynomial ring it could be quite fast. sage: # create your variables but in a polynomial ring sage: # so arithmetic with them is *very* fast sage: R.<x,y> = QQ[] sage: p1 = transpose(matrix([[x1,y1,z1]])) sage: p2 = transpose(matrix([[x2,y2,z2]])) sage: p3 = transpose(matrix([[x3,y3,z3]])) sage: alpha = p2 - p1; alpha [-x1 + x2] [-y1 + y2] [-z1 + z2] sage: beta = p3 - p1 sage: alpha[0] (-x1 + x2) sage: m = matrix(3,3,[x,y,z, alpha[0][0], alpha[1][0], alpha[2][0], beta[0][0], beta[1][0], beta[2][0]]) sage: m [ x y z] [-x1 + x2 -y1 + y2 -z1 + z2] [-x1 + x3 -y1 + y3 -z1 + z3] Note that arithmetic with m will be billions of times faster than with the formal symbolic variables. E.g., the following is instant, and results in a matrix each of whose entries is over 4000 characters long: sage: time n = m^5 CPU time: 0.00 s, Wall time: 0.00 s sage: len(str(n[0,0])) 4788 ----- Here is a SAGE notebook version of the above session. poly matrix system:sage {{{id=0| # create your variables but in a polynomial ring # so arithmetic with them is *very* fast R.<x1,y1,z1, x2,y2,z2, x3,y3,z3, p1,p2,p3, x,y,z, alpha, beta> = QQ[] }}} {{{id=1| p1 = transpose(matrix([[x1,y1,z1]])) }}} {{{id=2| p2 = transpose(matrix([[x2,y2,z2]])) }}} {{{id=3| p3 = transpose(matrix([[x3,y3,z3]])) }}} {{{id=4| alpha = p2 - p1; alpha /// [-x1 + x2] [-y1 + y2] [-z1 + z2] }}} {{{id=5| beta = p3 - p1 }}} {{{id=6| alpha[0] /// (-x1 + x2) }}} {{{id=7| m = matrix(3,3,[x,y,z, alpha[0][0], alpha[1][0], alpha[2][0], beta[0][0], beta[1][0], beta[2][0]]) }}} {{{id=8| m /// [ x y z] [-x1 + x2 -y1 + y2 -z1 + z2] [-x1 + x3 -y1 + y3 -z1 + z3] }}} {{{id=9| time n = m^5 /// CPU time: 0.00 s, Wall time: 0.00 s }}} {{{id=10| len(str(n[0,0])) /// 4788 }}} {{{id=11| }}} --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~----------~----~----~----~------~----~------~--~---