0
$\begingroup$

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]
$\endgroup$

3 Answers 3

1
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ This works flawlessly. Amazing. Thank you very much! $\endgroup$
    – Giorgio GG
    Nov 5, 2020 at 13:34
1
$\begingroup$

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)*)
$\endgroup$
4
  • $\begingroup$ 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 $\endgroup$
    – Giorgio GG
    Nov 5, 2020 at 13:35
  • $\begingroup$ 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. $\endgroup$
    – Hugh
    Nov 5, 2020 at 13:48
  • $\begingroup$ @GiorgioGG Try to restart your kernel. $\endgroup$ Nov 5, 2020 at 14:01
  • $\begingroup$ @Ulrich Neumann is right. Now it is working. Thanks! $\endgroup$
    – Giorgio GG
    Nov 5, 2020 at 14:32
0
$\begingroup$

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]
$\endgroup$

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.