2
$\begingroup$

Please I need help to solve this heat equation with this particular boundary conditions: This the Code I tried in Mathematica:

(*Numerical solution*)
homogene = {D[g[x, t], {t, 1}] - D[g[x, t], {x, 2}] == 0};
(*Initial conditions*)
ice = {g[x, 0] == x*(1 - x)};
(*Dynamic boundary conditions*)
bce = {D[g[0, t], {t, 1}] - D[g[0, t], {x, 1}] == 0, 
   D[g[1, t], {t, 1}] + D[g[1, t], {x, 1}] == 0};
(*solution*)
sol11 = (NDSolve[{homogene, ice, bce}, g, {x, 0, 1}, {t, 0, 1}, 
   MaxStepSize -> 0.1])

As a result, I get this error: NDSolve::bdord: Boundary condition (g^(0,1))[0,t] should have derivatives of order lower than the differential order of the partial differential equation.

$\endgroup$
2
  • $\begingroup$ You have first order in time PDE, but you are supplying bc which contains derivative w.r.t time. You can't do that. The order of BC/IC should be lower than the order in the PDE. D[g[0, t], {t, 1}] This is like with normal ODE. If you have first order ODE to solve, then initial conditions can't be first order derivative. $\endgroup$
    – Nasser
    Jun 23, 2021 at 9:25
  • $\begingroup$ @Nasser You make it clear for me, thank you. Is there is any other method we can apply to solve this problem? $\endgroup$
    – walid fssm
    Jun 23, 2021 at 10:45

1 Answer 1

2
$\begingroup$

We can use method of lines to solve this problem as follows

np = 40;
ugrid = 1/np Range[0, np];



fd1 = NDSolve`FiniteDifferenceDerivative[Derivative[1], ugrid]; fd2 = 
 NDSolve`FiniteDifferenceDerivative[Derivative[2], ugrid]; m1 = 
 fd1["DifferentiationMatrix"]; m2 = 
 fd2["DifferentiationMatrix"]; vart = 
 Table[u[i][t], {i, Length[ugrid]}]; uxx = m2 . vart; ux = 
 m1 . vart; var = Table[u[i], {i, Length[ugrid]}];
u0[x_] := x (1 - x);
eqns = Join[{D[u[1][t], t] == First[ux], 
    D[u[np + 1][t], t] == -Last[ux]}, 
   Table[D[u[i][t], t] == uxx[[i]], {i, 2, np}]];
ics = Table[u[i][0] == u0[ugrid[[i]]], {i, Length[ugrid]}];

tmax = 1;
sol = NDSolve[{eqns, ics}, var, {t, 0, tmax}];

Visualization

lst = Flatten[
   Table[{t, ugrid[[i]], u[i][t] /. sol[[1]]}, {t, 0, 1, .01}, {i, 1, 
     Length[ugrid]}], 1];
ListPlot3D[lst, Mesh -> None, PlotRange -> All, 
 AxesLabel -> {"t", "x", "g"}, ColorFunction -> "Rainbow", 
 Boxed -> False]

Figure 1

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