# Piecewise Initial Conditions in NDSolve

**URL:** <https://community.wolfram.com/t/piecewise-initial-conditions-in-ndsolve/755>\
**Category:** Questions\
**Tags:** mathematica, calculus, equation-solving\
**Created:** [October 22, 2013, 7:33am UTC](https://community.wolfram.com/t/piecewise-initial-conditions-in-ndsolve/755 "2013-10-22T07:33:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zharenkovda](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@zharenkovda](https://community.wolfram.com/u/zharenkovda)\
**Post date:** [October 22, 2013, 7:33am UTC](https://community.wolfram.com/t/piecewise-initial-conditions-in-ndsolve/755/1 "2013-10-22T07:33:01Z")

</div>

Hello,  
I’m trying to solve the system like this. The main problem is piecewise initial conditions. I tried to use Piecewise function in Mathematica, but Mathematica throws an error

```auto
"The first argument {1,0<=thet<=\[Pi]/6} of Piecewise is not a list \
of pairs. "

```

 ![newcond.jpg](https://global.discourse-cdn.com/wolfram/original/2X/0/0e50e1650864a665a7832f191123cd2a11235531.jpeg)  
What is my mistake? Here’s the code

```auto
c = 100;
b = 1; 
a = 1.01;
mu = 1;
r0 = 0.1;

w = NDSolve[{D[u[r, thet, t], t] == 
    D[u[r, thet, t], {r, 2}] + (1/r) D[u[r, thet, t], r] + (1/r^2) D[
       u[r, thet, t], {thet, 2}] + 
     u[r, thet, t] (1 - u[r, thet, t] - c*x[r, thet, t]),
   D[x[r, thet, t], t] == 
    mu*(D[x[r, thet, t], {r, 2}] + (1/r) D[x[r, thet, t], 
          r] + (1/r^2) D[x[r, thet, t], {thet, 2}]) + 
     a*x[r, thet, t] (1 - c*u[r, thet, t] - b*x[r, thet, t]),
   D[u[r, thet, t], r] == 0 /. {r -> 1},
   D[x[r, thet, t], r] == 0 /. {r -> 1},

   u[r, thet, 0] == 
    Piecewise[{{Piecewise[{1, 0 <= thet <= Pi/6}, {0, 
         Pi/6 < thet < 2 Pi}], r <= r0}}, {0, r > r0}],
   x[r, thet, 0] == u[r, thet, 0] == 
    Piecewise[{{Piecewise[{0, 0 <= thet <= Pi/6}, {1, 
         Pi/6 < thet < 2 Pi}], r <= r0}}, {0, r > r0}],
   }, {u[r, thet, t], x[r, thet, t]}, {t, 0, 100}, {r, 0, 1}, {thet, 
   0, 2 Pi}]

```

Thanks!

---

<div class="post-metadata">

**Author:** ![zharenkovda](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@zharenkovda](https://community.wolfram.com/u/zharenkovda)\
**Post date:** [October 22, 2013, 4:35pm UTC](https://community.wolfram.com/t/piecewise-initial-conditions-in-ndsolve/755/2 "2013-10-22T16:35:11Z")

</div>

Solution found, thanks

---

<div class="post-metadata">

**Author:** ![wolframcommunity](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/wolframcommunity/32/8335_2.png) [@wolframcommunity](https://community.wolfram.com/u/wolframcommunity)\
**Post date:** [October 22, 2013, 7:27pm UTC](https://community.wolfram.com/t/piecewise-initial-conditions-in-ndsolve/755/3 "2013-10-22T19:27:12Z")

</div>

Danila, could you please post your solution?

---

<div class="post-metadata">

**Author:** ![zharenkovda](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@zharenkovda](https://community.wolfram.com/u/zharenkovda)\
**Post date:** [October 23, 2013, 11:36am UTC](https://community.wolfram.com/t/piecewise-initial-conditions-in-ndsolve/755/4 "2013-10-23T11:36:23Z")

</div>

Here’s the solution, the mistake was with brackets

```auto
w = NDSolve[{D[u[r, thet, t], t] == 
    D[u[r, thet, t], {r, 2}] + (1/r) D[u[r, thet, t], r] + (1/r^2) D[
       u[r, thet, t], {thet, 2}] + 
     u[r, thet, t] (1 - u[r, thet, t] - c*x[r, thet, t]),
   D[x[r, thet, t], t] == 
    mu*(D[x[r, thet, t], {r, 2}] + (1/r) D[x[r, thet, t], 
          r] + (1/r^2) D[x[r, thet, t], {thet, 2}]) + 
     a*x[r, thet, t] (1 - c*u[r, thet, t] - b*x[r, thet, t]),
   D[u[r, thet, t], r] == 0 /. {r -> 1},
   D[x[r, thet, t], r] == 0 /. {r -> 1},
   D[u[r, thet, t], r] == 0 /. {r -> 0.01},
   D[x[r, thet, t], r] == 0 /. {r -> 0.01},
   u[r, thet, 0] == 
    Piecewise[{{Piecewise[{{0, 0 <= thet <= Pi/6}, {1, 
          Pi/6 < thet < 2 Pi}}], r <= r0}, {0, r > r0}}],
   x[r, thet, 0] == 
    Piecewise[{{Piecewise[{{1, 0 <= thet <= Pi/6}, {0, 
          Pi/6 < thet < 2 Pi}}], r <= r0}, {0, r > r0}}]}, {u[r, thet,
     t], x[r, thet, t]}, {t, 0, 10}, {r, 1}, {thet, 2 Pi}]

```
