1

I am only beginning to learn to use Mathematica, and got stuck while trying to implement what is apparently a simple substitution rule.

So I have a second order ODE in f, and I want to put in the ansatzf = r*phi, a multiplicative ansatz. I thought ReplaceAll followed by Simplify would do the job, but apparently this doesn't expand and simplify the derivatives. I want the replaced ODE to be in terms of r and phi only, no f, so that I can then manipulate them further. How to accomplish this?

Also, a side question, does someone know of a way to get to display the ODE in the proper form, all y'', y' and y terms grouped together? (for aesthetic purposes only)

The code:

J[k_,f_] := f''[k] +f'[k] +f[k]
J[k,f] //ReplaceAll[f[k] -> r[k] phi[k]] //Simplify

The output is :

r[k] phi[k] + f'[k] + f''[k]

I want the derivatives to be expanded/evaluated too.

Razor
  • 111
  • 3

1 Answers1

3

Two ways:

J[k_, f_] := f''[k] + f'[k] + f[k]
J[k, r[#] phi[#] &] // Simplify

Or

J[k, f] /. f -> (r[#] phi[#] &) // Simplify

Out:

(*  {2 phi'[k] r'[k] + r[k] (phi'[k] + phi''[k]) + phi[k] (r[k] + r'[k] + r''[k])}  *)

One can go further, too:

J[k, f]/f[k] /. f -> (r[#] phi[#] &) // Expand;
% /. {r'[k] -> lr'[k] r[k], phi'[k] -> lphi'[k] phi[k], 
    r''[k] -> (lr''[k] + lr'[k]^2) r[k], 
    phi''[k] -> (lphi''[k] + lphi'[k]^2) phi[k]} // Factor;
% /. lr -> (Integrate[u[#], #] - lphi[#] &) // Expand
(*  1 + u[k] + u[k]^2 + u'[k]  *)

where $\int u(k) \;dk = \log r(k) + \log \phi(k)$.

Michael E2
  • 235,386
  • 17
  • 334
  • 747