1
$\begingroup$

I have take time to be continuous to solve in NDSolve and space to be discrete, I have to put condition on the density function at every equation. This is how I am implementing this in my code.

eqn :=  Table[ Subscript[u, i]'[t] == 
    Subscript[u, i + 1][t] - 2 Subscript[u, i][t] + 
    Subscript[u, i - 1][t] +Subscript[u, i + 1][t] - 2 Subscript[u, i][t] + Subscript[u, i - 1][t] +HeavisideTheta[Subscript[u, i][t] - 0.047] , {i, 1, Xmax - 1}]


 iv = Table[
   If[(i >= 10) && (i <= 30), Subscript[u, i][0] == 1/21, 
    Subscript[u, i][0] == 0], {i, 0, Xmax}];

 s10 = NDSolve[{eqn, iv, bcs}, var, {t, 0, Tmax}];                  

This code is not working heaviside function is used to provide cut off on the function u.

$\endgroup$
2
  • 1
    $\begingroup$ I would not use subscripts if I were you. They tend to cause more problems than worth it. $\endgroup$
    – Nasser
    Commented Jul 19, 2018 at 6:13
  • $\begingroup$ Then what is the alternative, there are n differential equation, how to handle that $\endgroup$ Commented Jul 19, 2018 at 6:34

1 Answer 1

4
$\begingroup$
    Xmax = 50; Tmax = 1; eqn = 
 Table[Subscript[u, i]'[t] == 
   2*(Subscript[u, i + 1][t] - 2 Subscript[u, i][t] + 
       Subscript[u, i - 1][t]) + 
    HeavisideTheta[Subscript[u, i][t] - 0.047], {i, 1, Xmax - 1}];

bcs = {Subscript[u, 0][t] == 0, Subscript[u, Xmax][t] == 0};
iv = Table[
   If[(i >= 10) && (i <= 30), Subscript[u, i][0] == 1/21, 
    Subscript[u, i][0] == 0], {i, 0, Xmax}];

s = NDSolveValue[{eqn, iv, bcs}, 
   Table[Subscript[u, i][t], {i, 1, Xmax - 1}], {t, 0, Tmax}];
{Plot[s, {t, 0, Tmax}, AxesLabel -> {"t", u}], 
 ListLinePlot[Table[s, {t, 0, 1, .1}], AxesLabel -> {x, u}]}

fig1

$\endgroup$
2
  • $\begingroup$ Is there any other method to put cut off apart from heaviside theta function because it is taking too much time when i increase Tmax and lower the cut off of the order say 0.00047 $\endgroup$ Commented Jul 19, 2018 at 10:08
  • $\begingroup$ Specify the parameters and how much the calculation occupies. I find the code very fast, others can be slower. $\endgroup$ Commented Jul 19, 2018 at 17:58

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.