3
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ 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]"]] $\endgroup$
    – Michael E2
    Commented Apr 25, 2020 at 15:07

2 Answers 2

4
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Thank you very much. In addition, how to generate independent parameters like those in the picture of this problem (for example, only one parameter C)? $\endgroup$ Commented Mar 17, 2020 at 2:02
  • 1
    $\begingroup$ Try ClearAll[f]; f[i_Integer] := Subscript[\[DoubleStruckF], i]. See the Special Characters guide. $\endgroup$
    – Edmund
    Commented Mar 17, 2020 at 2:23
5
$\begingroup$

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

$\endgroup$
1
  • 2
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Apr 25, 2020 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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