3

I want to generate alphabetical parameters in the differential solution as shown in the figure below: $$\left(\frac{\mathrm d^2}{\mathrm d r^2}+\frac1{r}\frac{\mathrm d}{\mathrm d r}\right)\left(\frac{\mathrm d^2\phi}{\mathrm d r^2}+\frac1{r}\frac{\mathrm d\phi}{\mathrm d r}\right)=0$$

$$\phi=A\ln r+B r^2\ln r+C r^2+D$$ But I get a lot of error warnings when I do this:

L = (D[#, {r, 2}] + 1/r D[#, r]) &;
f[i_] := FromCharacterCode[i + 64]
DSolve[L[(D[φ[r], {r, 2}] + 1/r D[φ[r], r])] == 
  0, φ[r], r, GeneratedParameters -> f]

What can I do to solve this problem better?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • 1
    Note that C, D, E, I, etc. are System` symbols, usually with built-in definitions that will cause trouble later. Best to avoid capitals. Perhaps formal capitals?: DSolve[y''[x] == 3 y[x] y'[x] + (3 y[x]^2 + 4 y[x] + 1), y[x], x] /. C[i_] :> FromCharacterCode[ i + 1 + ToCharacterCode["\[FormalCapitalA]"]] – Michael E2 Apr 25 '20 at 15:07

2 Answers2

5

Why not replacing afterwards?:

i = 65;
DSolve[L[(D[φ[r], {r, 2}] + 1/r D[φ[r], r])] == 0, φ[r], r] /. 
  C[_] :> FromCharacterCode[i++]

enter image description here

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • 2
    This approach does not work on DSolve[y''[x] == 3 y[x] y'[x] + (3 y[x]^2 + 4 y[x] + 1), y[x], x]. Better to use DSolve[y''[x] == 3 y[x] y'[x] + (3 y[x]^2 + 4 y[x] + 1), y[x], x] /. C[i_] :> FromCharacterCode[i + 64], though it's better to avoid capitals. – Michael E2 Apr 25 '20 at 15:04
4

Two issues

  1. Define f for Integer.
  2. Return a Symbol.

Technically you can return the string as you are now but you will run into issues down the line.

ClearAll[f]
L = (D[#, {r, 2}] + 1/r D[#, r]) &;
f[i_Integer] := Symbol@FromCharacterCode[i + 64]

Then

DSolve[L[(D[φ[r], {r, 2}] + 1/r D[φ[r], r])] == 0, φ[r], r, GeneratedParameters -> f]

Mathematica graphics

without errors.

Hope this helps.

PS: You may also run into issues with symbols like C and I. This is why it is not recommended to define symbols (outside of packages) that start with capital letters. See here.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Edmund
  • 42,267
  • 3
  • 51
  • 143