﻿ Euler Math Toolbox - Examples

# Child and Toy Tracks

by R. Grothmann

```>load "child";
```

This notebook demonstrates solutions to the child and toy problem. A child is walking in the plane with a toy at the other end of a long stick. The problem is to determine the path of the toy.

The above Euler file contains functions for the numerical solution of the problem. The problem can be formulated as a differential equation, and we use the method of Heun to solve this equation numerically.

In the first example the child walks once around the unit circle and the stick is one unit long.

```>{child,toy}=child("childcircle",[2,0],4*pi):
``` You can watch the following animation of the result.

```>animateresult(child,toy);
```

If the child continues to walk around the circle the toy will spiral to 0.

```>child("childcircle",[2,0],10*pi):
``` However, if the stick is a little longer than the radius of the circle, the child will eventually push the toy forward. This results in a nice picture.

```>{child,toy}=child("childcircle",[2.1,0],12*pi,r=3,n=400):
``` ```>animateresult(child,toy);
```

If the stick is twice as long as the radius, we get a rosette.

```>{x,y}=child("childcircle",[3,0],16*pi,r=3):
``` It is possible to pass own movements to the child function. E.g., we move a man along the x-axis with constant speed 1. We define a function which returns two vectors, the place and the speed.

```>function childy(t) := {[t,0],[1,0]}
```

Then we can use it to generate our curve.

```>{x,y}=child("childy",[0,1],3,a=-1,b=4,c=-1,d=4):
``` This problem can be solved exactly. The solution will be the so called tractrix. From the geometry, the differential equation is obvious.

```>eq &= 'diff(y,x)=-y/sqrt(1-y^2)
```
```                         dy          y
-- = - ------------
dx               2
sqrt(1 - y )

```

Maxima can solve this.

```>&assume(y>0); sol &= ode2(eq,y,x)
```
```                           2
2 sqrt(1 - y ) + 2              2
log(------------------) - sqrt(1 - y ) = x + %c
y

```

The solution is implicit, so we get a function from y to x. We need to find the correct constant.

```>&solve(sol with [x=0,y=1],%c); &solve(sol with %,x);  ...
function f(y)&=rhs(%)
```
```                           2
2 sqrt(1 - y )   2              2
log(-------------- + -) - sqrt(1 - y ) - log(2)
y          y

```

Now y runs from 0.01 to 1. We have to compute x=f(y).

```>y1=linspace(0.01,1,100); x1=f(y1);
```

The result looks like our previous plot.

```>plot2d(x1,y1,a=-1,b=4,c=-1,d=4,color=6,thickness=2):
``` Let us compare the true value of the last point in the curve, with our numerical simulation.

```>f(y[2,-1]), y[1,-1]
```
```2.00494602429
2.00494537813
```

For a more complicated example, the child walks along a sin curve.

```>type childsin
```
```function childsin (t)
return {[t,sin(t)],[1,cos(t)]}
endfunction
```

Now the child pushes the stick a short distance and then the stick stays behind it.

```>child("childsin",[2,2],4*pi,a=0,b=14,c=-7,d=7):
``` There is a similar problem, where a dog runs towards a moving man. The dog has constant speed. Assume, the man runs once around the circle. What is the path of the dog?

The speed of the man equals the speed of the dog.

```>{man,dog}=dog("dogcircle",[2,2],2*pi):
``` ```>animateresult(man,dog);
>{man,dog}=dog("dogcircle",[2,2],10*pi,speed=0.5,n=1000):
``` ```>animateresult(man,dog);
```

It is obvious that the dog approaches a circle with half the radius of the circle the man is running on.

```>plot2d(sqrt(dog^2+dog^2)):
``` ```>sqrt(dog^2+dog^2)[-1]
```
```0.499637562301
```

In the next example the man runs straight along the x-axis.

```>dog("dogline",[0,2],5,a=-2,b=6,c=-4,d=4):
``` Examples