4
$\begingroup$

I'm new to Mathematica and want to try it after MATLAB.

I want to solve two different PDEs using the same initial condition and boundary conditions.

(want to verify that the solution I got using separation of variables is the same).

The PDEs I want to solve are:

$$ \frac{\partial u}{\partial t} = \frac{1}{x}\frac{\partial}{\partial x} \bigg( x \frac{\partial u}{\partial x} \bigg)$$

$$ \frac{\partial u}{\partial t} = \frac{1}{x^2}\frac{\partial}{\partial x} \bigg( x^2 \frac{\partial u}{\partial x} \bigg)$$

The initial condition is:

$\qquad u(x,0) = 0$

The boundary conditions are:

$\qquad \lim_{x\rightarrow 0 } \frac{\partial u}{\partial x} = 0$ $\qquad u(1,t) = 1$$

Here's what I attempted:

heqn1 = D[u[x, t], t] == (1/x)*D[[x,t],x]*(x*D[u[x, t], x]);
heqn2 = D[u[x, t], t] == (1/x^2)*D[[x,t],x]*D[u[x, t], x];
ic = u(x,0) == 0;
bc = {D[u[0, t], x] == 0, u[1, t] == 1};
sol1 = DSolve[{heqn1, bc, ic}, u, {x, t}] /. {K[1] -> m}
sol2 = DSolve[{heqn2, bc, ic}, u, {x, t}] /. {K[1] -> m}

Could someone help me fix this?

$\endgroup$
4
  • 6
    $\begingroup$ Your code does not correspond to the equations shown. For example, heqn1 should be defined as heqn1 = D[u[x, t], t] == (1/x)*D[x*D[u[x, t], x], x]; $\endgroup$
    – Bob Hanlon
    Commented Jan 5, 2021 at 6:33
  • 6
    $\begingroup$ Change initial conditions to ic = u[x, 0] == 0 $\endgroup$ Commented Jan 5, 2021 at 7:05
  • 4
    $\begingroup$ D[u[0, t], x] is wrong. You ma write this e.g. D[u[x0,t],x0]/.x0->0 $\endgroup$ Commented Jan 5, 2021 at 9:38
  • 2
    $\begingroup$ Are you interested in symbolic solution only, or you just want to verify the solution you got using separation of variables? If the latter, an you add that solution? $\endgroup$
    – xzczd
    Commented Jan 6, 2021 at 4:27

1 Answer 1

2
$\begingroup$

One way is solve numerically, for first equation (you must edit code for second equation and works to):

sol = NDSolve[{D[u[x, t], t] - (1/x)*D[x*D[u[x, t], x], x] == 
NeumannValue[0, x == 0], DirichletCondition[u[x, t] == 1, x == 1],
DirichletCondition[u[x, t] == 0, t == 0]}, 
u, {x, 0, 1}, {t, 0, 1}, 
Method -> {"FiniteElement", 
"MeshOptions" -> {"MaxCellMeasure" -> 0.00001}}](*NDSolve spit out some errors but you can ignore it.*)

Plot[Table[u[x, t] /. sol, {x, 0, 1, 1/25}] // Evaluate, {t, 0, 1}, PlotRange -> All]
Plot3D[u[x, t] /. sol, {x, 0, 1}, {t, 0, 1}, AxesLabel -> Automatic, 
PlotRange -> All, PlotPoints -> 100]

enter image description here

I checked with Maple 2020.2 and the solution are almost exact (to my eye the surface is very similar :)).

$\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.