Message Boards Message Boards

5 Replies
0 Total Likes
View groups...
Share this post:

Issue with definition in symbolic manipulation

Posted 10 years ago


I was a heavy user of Mathematica during my Ph.D... Which is a bit far, now (12 years ago). I'm trying to use it again, but I'm getting mad with some subtle features. Here is the issue.

I define something like

OrderDev = 1; i = 0;

[Eta][x, t] := Sum [Subscript[K, n][t] x^(2 n)/(2 n)!, {n, 0, OrderDev}]; [CapitalDelta][x, z, t_] := z - Subscript[K, 0][t]; Subscript[[CapitalPhi], i][x, z, t] := -Sum [ Subscript[[Phi], i , n][t] Cos[ n x - i Pi] Exp[-n [CapitalDelta][x, z, t]], {n, 1, OrderDev}];

When I define, for example, Subscript[dxphi, i_][x, z, t_] := D[Subscript[[CapitalPhi], i][x, z, t], x]; It gives what I expect : E^(-z + Subscript[K, 0][t]) Sin[x] Subscript[[Phi], 0, 1][t]

But when I try to take the value of dxphi when z=eta[x,t], it seems to perform the derivation again. For example, if I ask what is Subscript[dxphi, i][x, [Eta][x, t], t] , instead of getting E^([K, 1][t] x^2 /2) Sin[x] Subscript[[Phi], 0, 1][t] , I get E^(-(1/2) x^2 Subscript[K, 1][t]) Sin[x] Subscript[[Phi], 0, 1][t] + E^(-(1/2) x^2 Subscript[K, 1][t]) x Cos[x] Subscript[K, 1][t] Subscript[[Phi], 0, 1][t]

Meaning that it re-runs the initial definition, and so uses the chain rule.

How can I prevent this behavior, "freeze" the definition of the function and just getting its formal value at a point (for example, when z=eta[x,t]) ?

Thanks a lot

5 Replies
Posted 10 years ago

Oh, I'm sorry, I wasn't aware of those possibilities.

So once again. Here is a sample code :

    ClearAll[Eta, CapitalPhi, Phi, Delta, OrderDev, x, z, t, i, n, K, dxphi, dzphi, dxphis, dzphis];

    OrderDev = 1;
    i = 0;

    Eta[x_, t_] := Sum [K[n][t] x^(2 n)/(2 n)!, {n, 0, OrderDev}];
    Delta[ z_, t_] := z - K[0][t];
    CapitalPhi[x_, z_,  t_] := -Sum [Phi[n][t] Cos[n x - i Pi] Exp[-n Delta[z, t]], {n, 1, OrderDev}];
    dxphi[x_, z_, t_] := D[CapitalPhi[x, z, t], x];
    dzphi[x_, z_, t_] := D[CapitalPhi[x, z, t], z];

    dxphis[x_, t_] := dxphi[x, Eta[x, t], t];
    dzphis[x_, t_] := dzphi[x, Eta[x, t], t];

Mathematica doesn't understand what I say, which shows that I'm saying it wrong. When I ask

dxphi[x, z, t]

It answers

E^(-z + K[0][t]) Sin[x] Phi[1][t]

Which is OK with me, but then,

dxphis[x, t]


E^(-(1/2) x^2 K[1][t]) Sin[x] Phi[1][t] + E^(-(1/2) x^2 K[1][t]) x Cos[x] K[1][t] Phi[1][t]

When I expect

E^(-(1/2) x^2 K[1][t]) Sin[x] Phi[1][t]

Worse, in the case of

dzphis[x, t]

It says

General::ivar: K[0][t]+1/2 x^2 K[1][t] is not a valid variable. >>

So I assume that when I say something like $g(x)= {\partial f \over \partial x}$ and then $h(x) = g(u(x))$, it keeps the memory of the definition of $g$ and gives ${\partial f \over \partial x} (u(x)) \times u'(x)$, while I was looking for ${\partial f \over \partial x}| _ {\ u(x)}$.

Could you help me to define dxphis and dzphis in a proper way ?

Thank you in advance for your attention.


This may get you closer to what you want.

dzphi[x_, z_, t_] :=  Module[{zz}, D[CapitalPhi[x, zz, t], zz] /. zz -> z]

Now we get this.

In[376]:= dzphis[x, t]

Out[376]= E^(-(1/2) x^2 K[1][t]) Cos[x] Phi[1][t]
POSTED BY: Daniel Lichtblau
Posted 10 years ago

Yes, that's what I had discover. Thank you very much for your help. :)


A quick tutorial on the code formatting tools is in

Subscripts in executable code need help. See the notebook attachment SubscriptedVariables101.nb in thread for suggestions.

POSTED BY: Bruce Miller

Could you edit your post to make use of the formatting tools (in particular the code sample tool) so that your code is more readable and so that some special characters are not dropped? That will make it so that folks can play with it by copying and pasting into Mathematica and advise you.


POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract