1
$\begingroup$

I have two functions

    G[x_]:=x^6;
    S[x_]:=G[x]+x^12

I would like to operate on S[x] with respect to x in three ways, where we take the differentiation as an example for an operator

  1. Plug in G[x] in S[x] and then differentiate

  2. Do not plug in G[x] in S[x] and differentiate, such that x^12 is evaluated, but G[x] is only evaluated symbolically to G'[x]

  3. Do not plug in G[x] in S[x] and regard G[x] as a constant.

While 1. has an obvious solution, do you have an idea how to realize 2. and 3. without changing the lines of code given above, in particular without re-defining G every time?

I tried to build an operator consisting of different elements such as Unevaluated, Defer, Inactivate, Hold and Replace, but either G[x] gets plugged into S[x] or the differentiation is incorrect.

Can I give the function G[x] (temporarily) the Attribute "Constant" for 3.?

Best regards

$\endgroup$
1
$\begingroup$

Maybe you can use Block and Inactive:

S'[x]
Block[{G = Inactive[G]}, S'[x]]
Block[{G},
    G /: Derivative[1][G] = 0&; (* G is a constant *)
    With[{r = S'[x]},
        Inactivate[r, G]
    ]
]

6 x^5 + 12 x^11

12 x^11 + Inactive[G]'[x]

12 x^11

$\endgroup$
0
$\begingroup$

Here are some ways to approach this. For 1:

s[x_] := g[x] + x^12;
g[x_] = x^6;
D[s[x], x]
6 x^5 + 12 x^11

For 2:

Clear[g]
D[s[x], x]
12 x^11 + g'[x]

For 3:

g[x_] = c;
D[s[x], x]
12 x^11
$\endgroup$
  • $\begingroup$ Thank you for your attempt, but it is important not to change G[x_] every time. $\endgroup$ – Uwe.Schneider Aug 24 '18 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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