0
$\begingroup$

I have the following code:

x[t_]:=y[t]+2*t
MyRule = D[z[x[t]],x[t]]>0 

y[t] and z[x[t]] are unknown functions.

I get the following error message: "D: 2t+y[t] is not a valid variable". I suspect the message tells me that I can not take derivitates with respect to another function. But then what should I do? I know the easy solution here will be to just take the derivative with respect to t and y using the chain rule, but my real code consist of a lot of functions that depends on other functions why I really want this specific framework to work.

New contributor
Emil is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
4
  • $\begingroup$ Welcome to the Mathematica Stack Exchange. What is the desired output? Also please add a few test cases. $\endgroup$
    – Syed
    Commented Dec 11 at 12:29
  • $\begingroup$ you can not take derivative with respect to compound expression. It has to be single symbol. In the code you have, you are trying to take derivative wr.t. 2*t+y[t]. This is not a single variable/symbol. It has head Plus. $\endgroup$
    – Nasser
    Commented Dec 11 at 12:48
  • $\begingroup$ But then what should I do? could you show an actual case of what you want to do? not code., I mean the math,. You can show the input, and what you want the output to be. Then someone can show you how to do it in Mathematica. opps, I mean in the Wolfram Language. $\endgroup$
    – Nasser
    Commented Dec 11 at 13:07
  • $\begingroup$ I simply wants to state, that when x increases, I know that z will also increase. I need to use this statement later together with "Reduce", such that "Reduce" only give me the solutions, where this statement is true. $\endgroup$
    – Emil
    Commented Dec 11 at 13:14

2 Answers 2

0
$\begingroup$

Assume we have a function x[t] that depends an a function y[t]. And you would like to get the derivative of x[t] relative to y[t]. Toward this end, you could replace y[t] by a local variable, e.g. tmp, calculate the derivative relative to tmp. And finally replace tmp by y[t]:

myD[x_, y_] := Module[{tmp},
  D[x /.  y -> tmp, tmp] /. tmp -> y
]

With this e.g.:

x[t_] := 3 y[t]^2 + 2*t
myD[x[t], y[t]]

6 y[t]
$\endgroup$
0
$\begingroup$

The standard method of variational derivative of an axpression a wrt. to any expression b, that can be identified in a by a tree search is

D[  a/.{b -> $x},$x ]/.{$x->b}

here

x[t_]:=y[t]+2*t
MyRule = (D[ z[x[t]] /. {y[t] -> x - 2 t}, x] /. {x -> x[t]}) > 0

 Derivative[1][z][2 t + y[t]] > 0

This kind of derivative by lookup of occurencies of the expression b in the expression tree of a, just as it is presented, does not take care of any algebraic identities.

Use of such procedures with Replace makes sense only for function symbols without any additional algebraic entanglements with other symbols.

Especially for derivatives of a bunch of functions of one variable, follow the classical notational path of Newton/Leibniz/Euler of switching between symbolic function names and the same symbols with argument attached:

 vars= Union[Cases[expr, f_[t]:>f,Infinity]]

 Grad[ expr/.{f_[t]:>f}, vars]/.{ Rule@@@( Transpose[  {vars, Through[vars[t]] } ] )}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.