Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.8K Views
|
6 Replies
|
1 Total Like
View groups...
Share
Share this post:

[?] Perform a specific substitution in an expression?

Posted 8 years ago
POSTED BY: Ox Clouding
6 Replies

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
Posted 8 years ago

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

POSTED BY: Ox Clouding
Posted 8 years 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

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
Posted 8 years 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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard