5

In my program, there are many functions relying on spatial coordinates: x, y, and z, which are also functions of time t, i.e., composite function. I need to differentiate some functions for example f:

    D[f[x[t], y[t], z[t]], t]

But because those coordinates appear so frequently, when I write x[t] instead of x my program becomes lengthy and lacks readability. So, how can I declare those coordinates as functions of time t at the start to tell Mathematica that the differentiation is relative to t, so I can use x, y , and z, afterwards as an abbreviation.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
novice
  • 2,325
  • 1
  • 24
  • 30
  • 1
    You can use Dt as in Dt[f[x, y, z], t]. – b.gates.you.know.what Feb 17 '13 at 09:59
  • Thanks, I tried Dt[x^2, t], and Mma returns 2xDt[x, t]. whereas I need 2xx' – novice Feb 17 '13 at 12:08
  • The difference between Dt[x, t] and x' is : I can assign value to x', but I cannot assign value to Dt[x, t]. – novice Feb 17 '13 at 12:39
  • @user5463 No, you cannot assign a value to x'. It only seems you do it. Please read this answer of mine where I explain the details. – halirutan Feb 17 '13 at 12:47
  • Thanks halirutan, I have a little problem with the result of differentiation when i'm using Runge–Kutta method. For example, D[x[t]^2, t] returns 2x[t]*x'[t], i have to replace x'[t] with dx by hand so that I can assign value to dx, is there a convenient way to handle it automatically? – novice Feb 17 '13 at 14:41
  • Maybe x@t helps the readability. D[f[x@t, y@t, z@t], t] At least it avoids overloading brain with square brackets. – ssch Feb 17 '13 at 19:56
  • @user5463 Why dont you use a rule to replace each occurence of x'[t]? Something like D[x[t]^2, t] /. x'[t] -> dx. – halirutan Feb 17 '13 at 22:47

2 Answers2

3

No one stops you from creating a variable holding your Sequence of x[t], y[t] and z[t]! So an easy short cut is

vars = Sequence[x[t], y[t], z[t]];
D[f[vars], t]

When you need to access the single variables, you could go another way and use the formal characters which have some advantages as described in this answer

x = \[FormalX][t];
y = \[FormalY][t];
z = \[FormalZ][t];
D[f[x, y, z], t]
halirutan
  • 112,764
  • 7
  • 263
  • 474
3

Your added comment suggest you want to replace the derivatives with symbols like dx etc. Maybe this does what you want:

ClearAll[x, y, z]

SetOptions[D, NonConstants -> {x, y, z}];

x /: D[x, t, NonConstants -> {x, y, z}] := dx;
y /: D[y, t, NonConstants -> {x, y, z}] := dy;
z /: D[z, t, NonConstants -> {x, y, z}] := dz;

D[f[x, y, z], t]

dz*Derivative[0, 0, 1][f][x, y, z] + dy*Derivative[0, 1, 0][f][ x, y, z] + dx*Derivative[1, 0, 0][f][x, y, z]

To check that this does exactly what you said in the comments to your question:

D[x^2, t]

2 dx x

Jens
  • 97,245
  • 7
  • 213
  • 499