Message Boards Message Boards

[✓] 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.

POSTED BY: Ox Clouding
Answer
6 days ago

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]}]
POSTED BY: Gianluca Gorni
Answer
6 days 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!

POSTED BY: Ox Clouding
Answer
5 days 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
POSTED BY: Gianluca Gorni
Answer
5 days ago

Dear Glanluca, First thanks again for the reply. Sorry I didn't make it clear in my topic. But the whole point of setting up two lists "coor={x,y,z} and list={#1,#2,#3}" is to generalize to arbitrary dimensions, as described in the original post. The 3D test expression I give is just a special case.

I am trying to figure out why my substitution doesn't work - when e(i,j) is substituted by the derivative of a specified function u[i][x,y,z], it worked. When e(i,j) is substituted by (Evaluate[u[i] @@ list] &), it worked. But when I try to substitute e(i,j) with derivative of Evaluate[u[i] @@ list], it doesn't work. Why is that? Is there any way to do it correctly?

Thank you!

POSTED BY: Ox Clouding
Answer
5 days ago

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]
POSTED BY: Gianluca Gorni
Answer
5 days ago

That is exactly what I want to do! Now I understand where I got it wrong. Thank you!

POSTED BY: Ox Clouding
Answer
4 days ago

Group Abstract Group Abstract