[✓] Perform a specific substitution in an expression?

GROUPS:
 I was trying to substitute the "strain" in an expression with "displacement", and hopes to make it as general as possible in any dimensions. The relationship between the two is: e(i,j)=(du(i)/dx(j)+du(j)/dx(i))/2 where e(i,j) and u(i) are function of coordinates. So I first created two lists, coor={x,y,z} and list={#1,#2,#3}, which are special case for 3D. This two lists can be generated by other function so it can be generalized to other dimensions. Then, I try to substitute e(i,j) in some test expressions, like this one: D[e[1,2][x, y, z], y] But I don't know how to perform such a substitution, I have tried: D[e[1,2][x, y, z], y] /. e[i_ , j_] :> ((D[Evaluate[u[i] @@ list], coor[[j]]] + D[Evaluate[u[j] @@ list], coor[[i]]])/2 &) which doesn't work. But something like: D[e[1,2][x, y, z], y] /. e[i_ , j_] :> (Evaluate[u[i] @@ list] &) works fine. This is not what I want, though. I want to substitute the e(i,j) with derivative of u(i) instead. How can I achieve this?Thanks in advance!Edit: fix a mistake in the test expression.
6 months ago
6 Replies
 If I have not misunderstood, one way would be like this: sost = e[i_, j_] :> Function[((Derivative @@ UnitVector[3, j])[ u[i]][##] + (Derivative @@ UnitVector[3, i])[u[j]][##])/2]; e[1, 2][x, y, z] /. sost and another one is mat = D[Through[{u[1], u[2], u[3]}[x1, x2, x3]], {{x1, x2, x3}}]; Mean[{mat, Transpose[mat]}] 
6 months ago
 Hi Gianluca, Thank you for your reply. I have tried your solution on this test sample: sost = e[i, j] :> Function[((Derivative @@ UnitVector[3, j])[ u[i]][##] + (Derivative @@ UnitVector[3, i])[u[j]][##])/2]; D[e[1, 2][x, y, z],y] /. sost Which returns 0 on my computer. So I suppose it doesn't work.For the second solution, I agree it will work out if I enumerate all possible e[i,j] like that, but is there any way to avoid enumeration using the substitution rules?Thanks!
6 months ago
 Try this viariation: sost = e[i_, j_] :> Function[((Derivative @@ UnitVector[3, j])[ u[i]][#1, #2, #3] + (Derivative @@ UnitVector[3, i])[ u[j]][#1, #2, #3])/2]; e[1, 2][x, y, z] /. sost D[e[1, 2][x, y, z], y] /. sost 
 Gianluca Gorni 1 Vote It may be the order of evaluation: coor = {x, y, z}; list = {#1, #2, #3}; e[i_, j_] :> ((D[Evaluate[u[i] @@ list], coor[[j]]] + D[Evaluate[u[j] @@ list], coor[[i]]])/2 &) you can see that coor and list are not inserted into the rule. If you use With the values will be injected: With[{coor = {x, y, z}, list = {#1, #2, #3}}, e[i_, j_] :> ((D[Evaluate[u[i] @@ list], coor[[j]]] + D[Evaluate[u[j] @@ list], coor[[i]]])/2 &)] Another approach: sost[n_Integer] := e[i_, j_] :> Function[ Evaluate[((Derivative @@ UnitVector[n, j])[u[i]] @@ Array[Slot, n] + (Derivative @@ UnitVector[n, i])[u[j]] @@ Array[Slot, n])/2]]; e[1, 2][x, y, z] /. sost[3] D[e[1, 2][x, y, z], y] /. sost[3]