3

Let's say I have :

a*u''[x]+b*u'[x] 

where a and b are constant

I would need to get

(a*d2/dx2 + b*d/dx)u[x]

Can anyone tell me how I could to proceed?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
user15881
  • 33
  • 3
  • 1
    Do you mean you just want the output to be formatted in TraditionalForm? Then this could be a duplicate of How to make traditional output for derivatives. But I guess you want the factorization with u appearing only once on the right. Is that the main issue? In that case, is it OK to always assume that x is the independent variable? – Jens Jun 11 '14 at 18:40
  • Hi Jens, Yes I want to factorize u[x] where x is independent variable and u[x] represent u is a function of x – user15881 Jun 11 '14 at 19:12

1 Answers1

2

Since the desired form is not valid Mathematica code (for the operations it is supposed to represent), it has to be done using strings and/or HoldForm. Here is one way:

First I define the expression to be transformed:

expr = a*u''[x]+b*u'[x];

Then define the formatting of a variable dOp that is supposed to represent the differential operator or its powers. This is done using Format - for the first power and i-th powers separately.

ClearAll[dOp, i];

Power[dOp, i_] ^:= dOp[i];

Format[dOp] = "d/dx";

Format[dOp[i_]] := "d" <> # <> "/dx" <> # &[ToString[i]];

HoldForm[(#) u[x]] &[expr /. u -> (Exp[dOp #] &) /. x -> 0]

(b d/dx+a d2/dx2) u[x]

The last instruction takes expr and replaces u by an exponential function whose derivative with respect to x can then be calculated and yields appropriate powers of dOp. The above formatting then kicks in and gets applied to these powers.

At that stage, we have the form (b d/dx+a d2/dx2). Lastly, the function u[x] has to be put back at the end. This is done by the left-most part of the last line, HoldForm[(#) u[x]]& which then wraps the differential operator so that the order is maintained with u[x] on the right-hand side of the output. The HoldForm is added last because the previous manipulations wouldn't work if carried out inside of HoldForm.

Jens
  • 97,245
  • 7
  • 213
  • 499