How can I define a function which depends on a function of x? Something like this

f[u[x]_,u[x]']= u[x]' + a [x] u[x] +b[x]

I think I wasn't enaugh clear. If I define this function:


and I put x = a + b I obtain:

f[a + b] // Expand
a^2 + b^2 + 2ab

Now I want to define something similar for a function:

f[u[x]_, x] = D[u[x], x] + a[x]u[x]

And for I put this in input

 f[z[x]u[x], x]

I want to obtain for the output


Is it possible? Or I can only define the differential operator?:

diff1 = D[#, x] + a[x]# &
  • $\begingroup$ something like f[u_[x_]] := x, but defining a function that takes as a second argument the derivative of the first is more involved. $\endgroup$ – acl Feb 28 '15 at 19:12
  • 1
    $\begingroup$ a more detailed example of what you are trying to do might be helpful $\endgroup$ – george2079 Feb 28 '15 at 19:47
  • 1
    $\begingroup$ @ame_math Consider the definition f[g_, x_] := g[x] + g'[x]. On calling f you need to use the function g as a pure function. Expample: f[Cos[#]&,x] (* Cos[x] - Sin[x] *) $\endgroup$ – Dr. Wolfgang Hintze Feb 28 '15 at 21:16
  • $\begingroup$ If you define f as f[u_, x_] := D[u[x], x] + a[x] u[x] and evaluate f[u[#] z[#] &, x], you will get a[x] u[x] z[x] + z[x] u′[x] + u[x] z′[x], which I believe is what you are looking for. $\endgroup$ – m_goldberg Mar 1 '15 at 0:36

This works:

f[u_, x_] := D[u, x] + a[x] u

By way of explanation, everything is an expression, and there is nothing particularly special about functions. You and I know that this definition doesn't have lot of meaning for objects "u" that aren't functions, but Mathematica doesn't need to know that u is a function.


On the assumption that you have defined the functions u[x], a[x] and b[x] elsewhere, you can define a function as follows:

f[x_] := u'[x] + a[x] u[x] + b[x]

However, I recommend you read through the documentation on defining functions.

  • $\begingroup$ And if I defined only a[x] and not u[x] and u[x]', I suppose that u[x] is an rbitrary function, it could be also a product of functions u[x]=z[x]u[x]. $\endgroup$ – ame_math Feb 28 '15 at 18:00
  • $\begingroup$ The question is not entirely clear to me yet, either, but perhaps this is what you meant: f[u_, x_] := D[u, {x, 1}] + a[x] D[u, {x, 0}] + b[x] $\endgroup$ – TransferOrbit Feb 28 '15 at 20:16

I am still not sure of what you want but attempting to be helpful:

f[u[x] p_, x] := D[u[x] p, x] + a[x] u[x] p

f[z[x] u[x], x]
a[x] u[x] z[x] + z[x] Derivative[1][u][x] + u[x] Derivative[1][z][x]

Which formats as:

$a(x) u(x) z(x)+z(x) u'(x)+u(x) z'(x)$


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.