# Problem with NDSolve (and NDSolve) for piecewise definite system

I am using Mathematica 10.4 on Linux system and have the following issue. I have modeled a Dubins car: x, y is its position in the plan and gt, ht is its direction. u is the angular velocity. A basic idea I try to implement is to get the car closer to the origin. In particular, I want the angular velocity to be 0 when the car is reducing the distance to the origin, and turn on its left otherwise. I am not sure whether my idea is correct overall, but it is not the point as I am simply trying to simulate this simple system.

I have the following code:

    u:= 1
sysgt[x_, y_, gt_, ht_] :=
Piecewise[{
{0, ((x >= 0 && gt <= 0) || (x <= 0 && gt >= 0)) && ((y <= 0 &&
ht >= 0) || (y >= 0 && ht <= 0))},
{-u ht, True}},
-u ht]
sysht[x_, y_, gt_, ht_] :=  Piecewise[{
{0, ((x >= 0 && gt <= 0) || (x <= 0 && gt >= 0)) && ((y <= 0 &&
ht >= 0) || (y >= 0 && ht <= 0))},
{u gt, True}
},
u gt]
NDSolve[{x'[t] == gt[t],
y'[t] == ht[t],
gt'[t] == sysgt[x[t], y[t], gt[t], ht[t]],
ht'[t] == sysht[x[t], y[t], gt[t], ht[t]],
x[0] == 2, y[0] == 2, gt[0] == Sqrt[2]/2, ht[0] == Sqrt[2]/2},
{x[t], y[t], gt[t], ht[t]},
{t, 0, 20}]


As a result, I get this:

      ParametricPlot[{x[t], y[t]} /. sol, {t, 0, 20}]
ParametricPlot[{gt[t], ht[t]} /. sol, {t, 0, 20}]


These images shows that when the direction gt, ht points towards (-1,0), the angular velocity remains constant. It is actually supposed to stop once x is negative as the condition for using the constant speed is not satisfied here. It have evaluated some solutions that are returned NDSolve which explicitly shows that the angular speed should not be constant. Is it a problem with Piecewise ? Somehow, NDSolve seems to ignore the condition.

I tried to run the same sample code with DSolve (replace in the above code NDSolve by DSolve), but it is simply doing nothing.

Any help ?

• Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Oct 6 '16 at 12:48
• The definition of sysht contains syntax errors. With the errors corrected, DSolve returns unevaluated. Please check whether the code in the question is actually what you are using. As a rule of thumb, do not type your code into a question, copy and paste it from Mathematica. – bbgodfrey Oct 7 '16 at 12:40
• I have edited my message with the corrected sysht (there was extra brackets) and with the actual use of NDSolve instead of DSolve for which I got these plots. But I aslo tried with DSolve which seems to not evaluates anything. Why DSolve returns unevaluated in this example ? – B. Martin Oct 26 '16 at 8:39