RE: 2 Simple Mathematica Questions. (regarding tensors and matrices)
- To: mathgroup at smc.vnet.net
- Subject: [mg45118] RE: [mg45083] 2 Simple Mathematica Questions. (regarding tensors and matrices)
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 17 Dec 2003 07:54:34 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Ashok, For your first question you should use the Outer command. Amat = Array[A, {3, 3}]; Mmat = Array[M, {3, 3}]; Hmat = Outer[Times, Amat, Mmat]; Hmat[[1, 2, 3, 3]] A[1, 2] M[3, 3] On your second question, unfortunately you have to use a different name on the left hand side to avoid a rucursive definition. If you wish to try the Tensorial package at my web site I think you might find a more natural approach to these problems. It has an easy way of assigning tensor values and using index notation. You wouldn't have to make an Amat or Bmat matrix because there is already an index notation. Needs["TensorCalculus3`Tensorial`"] DefineTensorShortcuts[{{A, M}, 2}, {H, 4}] That creates tensor shortcuts for second rank A and M tensors and 4th rank H tensors. With tensor shortcuts defined, we can enter, say, an A tensor with two up indices as Auu[i,j], or with up and down indices as Aud[i,j] etc. You could enter the tensor product of A and M, and then expand it to a full array by the following statements... Auu[i, j]Muu[k, l] % // EinsteinArray[] EinsteinArray expands on the free indices in the expression. You could obtain a specific element with Auu[1, 2]Muu[3, 3] You could set values for the H tensor with SetTensorValues[Huuuu[i, j, k, l], Auu[i, j]Muu[k, l] // EinsteinArray[]] and then obtain the same value as above with Huuuu[1, 2, 3, 3] David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Ashok. R [mailto:ashokr at alum.dartmouth.org] To: mathgroup at smc.vnet.net Greetings. This is my first question: I am trying to form a 4-tensor, H, whose (i,j,k,l) components are given by H(i,j,k,l) = M(i,j)A(k,l) where M and A are 2-Tensors (Matrices). This is what I have been doing so far: L1 = Array[M, {3, 3}] L2 = Array[A,{3,3}] H = Table[L1[i,j]*L2[k,l] {i,3},{j,3},{k,3},{l,3}] The last statement gives a long output, but not the the correct result. I want to be able to say H[[1,3,2,1]] and get M[1,3]A[2,1] as output. Can someone familiar with tensor manipulation in Mathematica tell me how to do this ? ---------------------------------------------------------------------------- --------------------- This is my second question: I want to assign a matrix, A, that has three rows and three columns and each element is identified by A[i,j] L1 = Array[A,{3,3}] works, but the array is called L and not A. I tried A = Array[A,{3,3}] and that, as expected, gave me a warning about recursions. Thank you for your assistance. I wish you a pleasant day. Ashok