# How to calculate the derivative of the solution of DSolve?

It should be a particularly straightforward problem to solve. However I cannot manage to do it. I get a solution from a differential equation via DSolve. I just want to calculate now the derivative of this solution to respect to r. There is no way I can get this to work.

I've tried cA'[r], Derivative[1,0,0,0][cA], simpsol'[r], D[simpsol[r,R,cAR,phi],r].... i always get as output the same text I wrote, but not the derivative.

Is there a simple solution? I would like to keep the code simple and clean. How to extract this solution and use it for other calculations such as taking the derivative of the solution?

diffPD = {2/r*cA'[r] + cA''[r] == \[Phi]^2/R^2*cA[r], cA[R] == cAR,
cA'[0] == 0}
solPD = DSolve[diffPD, cA[r], r]
simpsol = FullSimplify[solPD]


I suggest you first extract the solution as follows

ex = cA[r] /. First@simpsol


Here I have named the output ex

(cAR R Csch[ϕ] Sinh[(r ϕ)/R])/r

Then we can take the derivative using D

D[ex, r]


Giving

(cAR ϕ Cosh[(r ϕ)/R] Csch[ϕ])/r - ( cAR R Csch[ϕ] Sinh[(r ϕ)/R])/r^2

Does that help?

• This works flawlessly. Amazing. Thank you very much! Commented Nov 5, 2020 at 13:34

For a simple solution try DSolveValue

diffPD = {2/r*cA'[r] + cA''[r] == \[Phi]^2/R^2*cA[r], cA[R] == cAR, cA'[0] == 0}
solPD = DSolveValue[diffPD, cA, r]


the solution of the ode is solPD[r] and the derivative follows to

solPD'[r]
(*-((cAR E^(\[Phi] - (r \[Phi])/R) (-1 + E^((2 r \[Phi])/R)) R)/((-1 + E^(2 \[Phi])) r^2)) + (2 cAR E^(\[Phi] + (r \[Phi])/R) \[Phi])/((-1 + E^(2 \[Phi])) r) - (cAR E^(\[Phi] - (r \[Phi])/R) (-1 + E^((2 r \[Phi])/R)) \[Phi])/((-1 + E^(2 \[Phi])) r)*)

• Thanks for the reply! I must have done something wrong because it doesn't work in my case. However, the solution provided by @Hugh worked :D Commented Nov 5, 2020 at 13:35
• Glad I could help. If you don't get a better answer in the next day or so please accept my answer so that the question is closed with a response that others can use.
– Hugh
Commented Nov 5, 2020 at 13:48
• @GiorgioGG Try to restart your kernel. Commented Nov 5, 2020 at 14:01
• @Ulrich Neumann is right. Now it is working. Thanks! Commented Nov 5, 2020 at 14:32

Solve it as

DSolve[{dcA[r] == cA'[r], 2/r dcA[r] + dcA'[r] == \[Phi]^2/R^2*cA[r], cA[R] == cAR, dcA[0] == 0}, {cA, dcA}, r]