home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 June / Chip_2002-06_cd1.bin / zkuste / derive / download / Setup.exe / %MAINDIR% / Users / Tensor1.dmo < prev    next >
Encoding:
Text File  |  2002-05-15  |  4.2 KB  |  142 lines

  1. "           The Derive Tensor Algebra and Analysis Package              "
  2. "   Demonstration File Tensor1.dmo to show various tensor operations    "
  3. "      Written by Hans A. Dudler (619 420-1787)  25 November 1994       "
  4. "      Updated for Derive 5                      10 November 2001       "
  5. "     For more detailed documentation, see the text file Tensor.doc     "
  6.  
  7. ; Load the Tensor.mth utility file
  8. LOAD("Tensor.mth")
  9.  
  10. ;
  11. "               *** BASIC TENSOR OPERATIONS  ***                      "
  12. " A simple tensor of rank 3, dimension 3 is the permutation tensor:   "
  13. ; Assign EPS(3) to E__ijk
  14. E__ijk:=EPS(3)
  15. ;
  16.  
  17. ; Determine rank (order) of tensor
  18. RANK_T(E__ijk)
  19.  
  20. ; Determine dimension of tensor
  21. DIM_T(E__ijk)
  22.  
  23. ; Extracting non-zero elements of E__ijk
  24. NZEL_T(E__ijk)
  25.  
  26. ; Collecting non-zero elements with equal absolute value (1 in this case)
  27. ; This shows skew symmetry (neg.indices indicate neg.value)
  28. GNZE_T(E__ijk)
  29.  
  30. ; Define a general covariant tensor T_ij (rank=2, dimension=3)
  31. T_ij:=[[A,B,C],[D,E,F],[G,H,I]]
  32.  
  33. ;
  34. " Implement the tensor formula  S__i = E__ijk T_jk :                  "
  35. " This can be done in 2 steps [there are 2 dummy (summation) indices]:"
  36. ;Summing over index j (= sS); result is mixed tensor of rank 3: T__ij_k
  37. ;(2 contravariant indices followed by a covariant index)
  38. T__ij_k:=IP_T(E__ijk,[iI,jJ,sS],T_ij,[kK,sS],[iI,jJ,kK])
  39.  
  40. ; Contracting indices j and k now gives the desired result
  41. S__i:=CT_T(T__ij_k,[iI,sS,sS],[iI])
  42.  
  43. ;Same thing can be done in one swoop using CI_T (contract inner product)
  44. S__i:=CI_T(E__ijk,[iI,sS,tT],T_ij,[sS,tT],[iI])
  45.  
  46. ;
  47. "              *** COORDINATE TRANSFORMATION  ***                     "
  48. " Going from X,Y,Z to spherical coordinates r,theta,phi               "
  49. ; New coordinates
  50. x_:=[r,theta,phi]
  51.  
  52. ; Old coordinates (as functions of new coordinates)
  53. x:=[r*SIN(theta)*COS(phi),r*SIN(theta)*SIN(phi),r*COS(theta)]
  54.  
  55. ; Jacobian matrix
  56. JM:=JACOB(x,x_)
  57.  
  58. ; Assign inverse to JM_
  59. JM_:=JM^-1
  60.  
  61. ; Old metric tensor (Cartesian coordinates)
  62. g_ij:=DELTA(3)
  63.  
  64. ; Transforming this to new coord.( 2 cov.indices, weight=0)
  65. g_ij_:=TF_T(g_ij,2,0,JM,JM_)
  66.  
  67. ; Since we are starting from a Cartesian frame, this is a simpler way
  68. g_ij_:=JM` . JM
  69.  
  70. ; Assigning dual (inverse) to g__ij_
  71. g__ij_:=g_ij_^-1
  72.  
  73. ; Christoffel symbols (assign to C_ijk_ and C_ij_k_)
  74. C_ijk_:=CHRIS1(g_ij_,x_)
  75.  
  76. ; Christoffel symbols (assign to C_ijk_ and C_ij_k_)
  77. C_ij_k_:=CHRIS2(g_ij_,g__ij_,x_)
  78.  
  79. ; The Riemann curvature tensor must be zero (Euclidian space): OK
  80. R_ijkl_:=RIEM1(C_ijk_,C_ij_k_,x_)
  81.  
  82. ; Definitions for following example
  83. [a:=,b:=,c:=,X:=ELEMENT(x,1)]
  84.  
  85. ; Example: A contravariant vector V__i in the old system
  86. V__i:=[a*X,b,c]
  87.  
  88. ; Transforming to new system (no cov.indices, weight=0)
  89. V__i_:=TF_T(V__i,0,0,JM,JM_)
  90.  
  91. ; We could have regarded V__i as covariant (Cartesian system)
  92. ; to get covariant dual of transformed vector
  93. V_i_:=TF_T(V__i,1,0,JM,JM_)
  94.  
  95. ; Vector length must be invariant: OK
  96. V_i_ . V__i_-V__i . V__i
  97.  
  98. ; Computing the covariant derivative of V_i_ (1 cov.index, 0 weight)
  99. DV_ij_:=CD_T(V_i_,1,0,x_,C_ij_k_)
  100.  
  101. ; Transforming this back to the old frame (JM and JM_ interchanged)
  102. ; we get the gradient tensor of the original vector: OK
  103. DV_ij:=TF_T(DV_ij_,2,0,JM_,JM)
  104.  
  105. ; To verify the identity  d/dx__j_ (g_ik_) = C_ijk_ + C_jki_
  106. ; find transpose C_jki_ (see discussion in Tensor.doc)
  107. C_jki_:=TP_T(C_ijk_,[jJ,kK,iI],[iI,jJ,kK])
  108.  
  109. ; Computing right-hand side
  110. rhs:=C_ijk_+C_jki_
  111.  
  112. ; Ordinary derivative of g_ij_
  113. g_ijk_:=OD_T(g_ij_,x_)
  114.  
  115. ; Computing left-hand side (transpose)
  116. lhs:=TP_T(g_ijk_,[iI,kK,jJ],[iI,jJ,kK])
  117.  
  118. ; Verify that lhs = rhs : OK
  119. lhs-rhs
  120.  
  121. ;
  122. "                *** NON-EUCLIDIAN SPACE  ***                            ":=~
  123. " Consider the latitude/longitude coordinates on the earth's surface :   "
  124. ; Defining coordinate system
  125. x:=[theta,phi]
  126.  
  127. ; Line element is   ds^2 = R^2*dtheta^2 + R^2*COS(theta)*dphi^2
  128. ; This is therefore the covariant metric tensor
  129. g_ij:=[[R^2,0],[0,R^2*COS(theta)^2]]
  130.  
  131. ; The contravariant metric tensor is the inverse
  132. g__ij:=g_ij^-1
  133.  
  134. ; Christoffel symbols
  135. C_ijk:=CHRIS1(g_ij,x)
  136.  
  137. ; Christoffel symbols
  138. C_ij_k:=CHRIS2(g_ij,g__ij,x)
  139.  
  140. ; Curvature tensor: Non-zero, non-Euclidian space !
  141. R_ijkl:=RIEM1(C_ijk,C_ij_k,x)
  142.