Expansion of expressions involving Einstein summation convention with Levi-Civita tensors
10 次查看(过去 30 天)
显示 更早的评论
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++.



Do you have any ideas on how I could do this?
1 个评论
David Goodmanson
2025-8-3
编辑:David Goodmanson
2025-8-4,4:15
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)]
回答(1 个)
Sameer
2025-8-4,10:08
编辑:Sameer
2025-8-4,10:09
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!