# PDE Solving in mathematica

I'd like to ask how I might go about solving this equation:

# $$\frac{\partial Ci}{\partial t} + \frac{1}{r^2}\frac{\partial (r^2 Ci)}{\partial r} = D\frac{1}{r^2}\frac{\partial}{\partial r}(r^2\frac{\partial Ci}{\partial r})$$

as suggested a simplification

# $$\frac{\partial Ci}{\partial t} + \frac{1}{r}2Ci +\frac{1}{r^2}\frac{\partial Ci}{\partial r} = D(\frac{2}{r}\frac{\partial Ci}{\partial r} +\frac{\partial^2 Ci}{\partial r^2})$$

$$r = 0, t = 0 \rightarrow Ci = 0$$
$$r = 1, t = 0 \rightarrow Ci = 0$$

I am fairly new to Mathematica and I don't really know how to go about this; I've also tried the steps outlined in this post here but while I understood what to do I get recursion limit reached errors (using the code provided).

Could you please help me out on how to solve this equation?

a partial and first attempt on solving this taking in account the notes of the posted link is the following:

Clear[y];
f1[r_ /; r > 0] := 1;
f1[r_ /; r == 0] := 2;
f2[r_ /; r > 0] := 1/r^2;
f2[r_ /; r == 0] := 0;
f3[r_ /; r > 0] := 1/r;
f3[r_ /; r == 0] := 0;

eqns = {
Derivative[0, 0, 1][y][t, r, z] +
f3[r]*2*y[t, r, z] +
f2*Derivative[0, 1, 0][y][t, r, z] -
2*f3[r]*Derivative[0, 1, 0][y][t, r, z] -
Derivative[0, 2, 0][y][t, r, z] == Derivative[1, 0, 0][y][t, r, z],
y[t, 0, z] == 0,
y[t, r, 0] == 0,
Derivative[0, 1, 0][y][t, 0, z] == 0,
Derivative[0, 0, 1][y][t, r, 0] == 0,
y[0, r, z] == (1 - r^2)*(1 - z^2)}

$RecursionLimit = 1536 y[t_, r_, z_] = y[t, r, z] /. First[NDSolve[eqns, y[t, r, z], {t, 0, 1}, {r, 0, 1}, {z, 0, 1}, Method -> {"MethodOfLines", Method -> "StiffnessSwitching", "DifferentiateBoundaryConditions" -> {True, "ScaleFactor" -> 1}}]];  This gives me a lot of errors but the first one is the following: • You do not provide any code. Commented Oct 18, 2013 at 21:16 • I said that I tried the code (tailored for my equation) that was supplied in the post I linked, do you need a more? Commented Oct 18, 2013 at 21:23 • Yes, at least the equation. Commented Oct 18, 2013 at 21:34 • Well, I have a problem with that I don't know how to type in the second partial; that is I don' know how to write the$\frac{\partial r^2Ci}{\partial r}$. This has both r and Ci inside which I don't how to type them. Commented Oct 18, 2013 at 22:05 • You mean D[ r^2 Ci[r,t], r] ? (I suppose Ci is a function of r and t). By the way, Ci and D are not the best names for variables in Mathematica. I'd switch to lowercase if I were you. At least for D. Commented Oct 18, 2013 at 22:47 ## 1 Answer Here is a solution using the method of characteristics. But the conditions as given above will cause a problem at$r=0$. There is no Cauchy data to use. So I kept the solution in terms of the constants of integrations. Let$u\left( t,r\right) be the solution \begin{align*} \frac{\partial u}{\partial t}+\frac{1}{r^{2}}\frac{\partial\left( r^{2}u\right) }{\partial r} & =D\frac{1}{r^{2}}\frac{\partial\left( r^{2}u\right) }{\partial r}\\ \frac{\partial u}{\partial t}+\frac{1}{r^{2}}\left( 2ru+r^{2}\frac{\partial u}{\partial r}\right) & =D\frac{1}{r^{2}}\left( 2ru+r^{2}\frac{\partial u}{\partial r}\right) \\ \frac{\partial u}{\partial t}+\left( 2\frac{u}{r}+\frac{\partial u}{\partial r}\right) & =D\left( 2\frac{u}{r}+\frac{\partial u}{\partial r}\right) \\ \frac{\partial u}{\partial t}+\frac{\partial u}{\partial r}\left( 1-D\right) & =-2\frac{u}{r}\left( 1-D\right) \end{align*} Let1-D=k, hence \begin{align*} \frac{\partial u}{\partial t}+k\frac{\partial u}{\partial r} & =-2k\frac {u}{r}\\ \frac{1}{k}\frac{\partial u}{\partial t}+\frac{\partial u}{\partial r} & =-2\frac{u}{r} \end{align*} To find the solution using the characteristics method, we write the above in the standard form $$\frac{dt}{k^{-1}}=\frac{dr}{1}=\frac{du}{-2\frac{u}{r}}%$$ Hencedt=\frac{dr}{k}$or$t=\frac{r}{k}+r_{0}$or $$r_{0}=t-\frac{r}{k}$$ Also,$\frac{du}{-2\frac{u}{r}}=dt$or$\frac{du}{u}=-\frac{2}{r}dt$, hence$\ln u=-\frac{2}{r}t+c_{2}$, or$u=Ae^{-\frac{2t}{r}}$. At$t=0$, to satisfy initial conditions at$r_{0}$, then$u\left( 0,r_{0}\right) =f\left( r_{0}\right) =A$. So the solution is $$u\left( t,r\right) =A\left( t-\frac{r}{k}\right) e^{-\frac{2kt}{r}}%$$ Mathematica gives this btw:  ClearAll[u, r, t, k]; ode = D[u[r, t], t] + k D[u[r, t], r] + 2 k u[r, t]/r sol = u[r, t] /. First@DSolve[ode == 0, u[r, t], {r, t}]  Again, I think the initial conditions given are not correct. for more information. • Thanks for the reply @Nasser; if that is the case then you can assume since we cannot solve for all$D$that$D$is$\frac{1}{2}$for that$k=\frac{1}{2}$. That way I get an answer but I don't think it is a correct one. Also the limits can be$0 \rightarrow 1$and if I do (sol /. {r -> 1, t -> 1}) == 0 I get an answer but that is a differential equation as well. Commented Oct 19, 2013 at 1:16 • This is a first order linear PDE, but it is inhomogeneous PDE. But you can still solve it analytically using separation of variables. You need to use eigenfunction expansion method. Commented Oct 19, 2013 at 1:23 • can you give me an example? The post I read had a similar equation for solving but I can't figure how to adapt my code to that code. Commented Oct 19, 2013 at 1:32 • @jtimz You can actually use the method of characteristics also to solve it? start by writing$\frac{dt}{1}=\frac{dr}{k}=\frac{du}{-2k\frac{u}{r}}$and then$\frac{dr}{dt}=k$or$r=tk+c_{1}$or$r-tk=c_{1}$and$\frac{du}{dt}=-2k\frac{u}{r}$or$\frac{du}{u}=-2\frac{k}{r}dt$, hence$\ln u=-2\frac{k}{r}t+c_{2}$, hence$u=c_{2}e^{-2\frac{k}{r}t}$So the the solution is function$f\left( r-tk,ue^{2\frac{k}{r}t}\right)\$. I just forgot more of the details now. Need to look it more...separation of variables will also work.... Commented Oct 19, 2013 at 2:13
• thanks will look it a bit more and will let you know! Thanks a ton! Commented Oct 19, 2013 at 2:27