# [IndexedBase](https://stackoverflow.com/questions/37647370/expand-index-notation-equation-using-sympy)
> ### that is, symbols indexed by other symbols

# $$
\sigma_{ij} = \lambda U_{k,k}\delta_{ij} + \mu(U_{i,j} + U_{j,i})
$$ 
> ### comma($U_{k,k}$) is a convention for derivative
> ### $U_1, U_2, U_3$ are written as u,v,w
> ### $x_1, x_2, x_3$ are written as x,y,z


```python
import sympy as sm
U = sm.IndexedBase('U')
i,j,k,l,mu,x,y,z = sm.symbols('i j k lambda nu x y z')
u,v,w = sm.symbols('u v w',cls=sm.Function)

sij = l*sm.Sum(U[k,k],(k,0,2)) * sm.KroneckerDelta(i,j)
l*sm.Sum(U[k,k],(k,0,2)) * sm.KroneckerDelta(i,j) + mu*(U[i,j] + U[j,i])
## replace
du = sm.derive_by_array([u(x,y,z), v(x,y,z),w(x,y,z)],[x,y,z])
l*sm.tensorcontraction(du,(0,1))
```




$\displaystyle {U}_{i,j}$



### $$ \sigma_x = \lambda\Big(\frac{\partial u}{\partial x} + \frac{\partial v}{\partial y} + \frac{\partial w}{\partial z} \Big) 
+ 2\mu \frac{\partial u}{\partial x} $$
### $$ \sigma_y = \lambda\Big(\frac{\partial u}{\partial x} + \frac{\partial v}{\partial y} + \frac{\partial w}{\partial z} \Big) 
+ 2\mu \frac{\partial v}{\partial y} $$
### $$ \sigma_z = \lambda\Big(\frac{\partial u}{\partial x} + \frac{\partial v}{\partial y} + \frac{\partial w}{\partial z} \Big) 
+ 2\mu \frac{\partial w}{\partial z} $$
### $$ 
\tau_{xy}= \mu\Big( \frac{\partial u}{\partial y} + \frac{\partial v}{\partial x}\Big),
\\ \tau_{yz}= \mu\Big( \frac{\partial v}{\partial z} + \frac{\partial w}{\partial y}\Big),
\\ \tau_{zx}= \mu\Big( \frac{\partial w}{\partial x} + \frac{\partial u}{\partial z}\Big),
$$


```python
# U[0,0] -> Derivative(u,x)
def replace_U(uij):
    i1, i2 = uij,indices
    return sm.Derivative([u,v,w][i1],[x,y,z][i2])
for ii in range(3):
    for ji in range(3):
        if ii < ji:
            continue
        sm.pprint(sij.doit().xreplace({i:ii, j:ji}).replace(lambda v: v.base == U,replace_U))
```


```python

```

99870889ce8101f1423631f2c40f277f340aa465
ipynb
Jupyter Notebook
python/Vectors/IndexedBase.ipynb
karng87/nasm_game
a97fdb09459efffc561d2122058c348c93f1dc87
MIT
python/Vectors/IndexedBase.ipynb
karng87/nasm_game
a97fdb09459efffc561d2122058c348c93f1dc87
MIT
python/Vectors/IndexedBase.ipynb
karng87/nasm_game
a97fdb09459efffc561d2122058c348c93f1dc87
MIT
Qwen/Qwen-72B
1. YES
2. YES