Expansion of expressions involving Einstein summation convention with Levi-Civita tensors
    11 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Dear all
I am evaluating expressions of the type

where all the subindices 
, and the dot on the variable m, 
, symbolizes the time derivative.
I'd be interested in being able to ask MatLab for the fully expanded 
, 
, and 
, so I can then numerically evaluate those terms. Ideally, it would be a plus if it also gave me the monstrous explicit expressions in LaTeX and/or could extrapolate the expanded expression to C++.
, 
, and 
, so I can then numerically evaluate those terms. Ideally, it would be a plus if it also gave me the monstrous explicit expressions in LaTeX and/or could extrapolate the expanded expression to C++.Do you have any ideas on how I could do this?
1 Kommentar
  David Goodmanson
      
      
 am 3 Aug. 2025
				
      Bearbeitet: David Goodmanson
      
      
 am 4 Aug. 2025
  
			Hi Roderick,  I am not sure what the advantage is in creating a monster list of all the terms, but the initial expression is a sum over 10 indices ( i being the free index not summed over).  You can reduce the sum to 7 indices before you start out.  The initial expression is
eps(abc)eps(def)eps(ijk)eps(kpq)  (a)(b)(jc)(d)(pe)(qf)
where on the right, just the indices are shown and not the objects they are attached to.  With the identiy 
eps(ijk)eps(kpq) = delta(ip)delta(jq) - delta(iq)delta(jp)      sum over k   
you can do the instant sums over p and q and arrive at 
eps(abc)eps(def)  (a)(b)(jc)(d) [(ie)(jf) - (je)(if)]
Antworten (1)
  Sameer
      
 am 4 Aug. 2025
        
      Bearbeitet: Sameer
      
 am 4 Aug. 2025
  
      Hi @Roderick
To expand tensor expressions involving Einstein summation and Levi-Civita symbols in MATLAB, you can use the Symbolic Math Toolbox along with a manual summation approach. 
1. Define symbolic variables and functions:
syms x y z t
syms m1(x,y,z,t) m2(x,y,z,t) m3(x,y,z,t)
2. Create Levi-Civita tensor:
epsilon = zeros(3,3,3);
epsilon(1,2,3) = 1; epsilon(2,3,1) = 1; epsilon(3,1,2) = 1;
epsilon(3,2,1) = -1; epsilon(1,3,2) = -1; epsilon(2,1,3) = -1;
epsilon = sym(epsilon);
3. Explicitly sum over indices:Use nested for loops to build the full expression by summing over all repeated indices. Combine derivatives using "diff()" and components like m1, m2, m3.
4. Simplify
T = simplify(expr);            % symbolic result
latex_str = latex(T);          % get LaTeX
c_code = ccode(T);             % get C code
Consider using helper functions from MATLAB File Exchange for Levi-Civita and Einstein summation (e.g. "Tensor Utilities").
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!