Matlab simulation of dog chasing a rabbit pursuit curve. Hi I'm really struggling with this problem of mine.
A rabbit is running along the x-axis ($0\to \infty$) with a constant velocity $v_r$ and a dog chases the rabbit starting at some point $L (0\cdots \infty)$ on the y-axis with a constant velocity $v_d$. The velocity vector of the dog is always pointing towards the rabbits location.
So I need the differential equation for the location of the dog and solve it numerically using matlab. To be exact, I need to plot the pursuit curve of the dog.
I also need to determine the time it takes to catch the rabbit (distance < 0.1m) at varying values of vr, vd and L (with matlab).
I can't make any sense of the examples I found over the past few days and can't figure out the use of ode45 function either.
I'd really appreciate your help. Thank you!
 A: Begin by formulating your system.
$$\begin{align*}
\frac{dx_r}{dt} &= v_r, \\
\frac{dy_r}{dt} &= 0, \\
\frac{dx_d}{dt} &= v_{dx}, \\
\frac{dy_d}{dt} &= v_{dy}.
\end{align*}$$
Now, $v_{dx}$ and $v_{dy}$ are determined by the vector from the rabbit to the dog. In other words, they proportional to $v_d$ as the component of the vector $(x_r-x_d, y_r-y_d)$ are proportional to its overall magnitude. In other words, you should get 
$$v_{dx} = v_d \cdot \frac{x_r-x_d}{\sqrt{(x_r-x_d)^2+(y_r-y_d)^2}}$$
and similarly for $v_{dy}$.
Now you have a first-order nonlinear system. You should be able to set up initial conditions, and ode45 should suit you just fine.
To use it, let's set up our function handle
%X = [x_r; y_r; x_d; y_d]
f = @(t,X)[v_r*(norm([X(1)-X(3); X(2)-X(4)])>.01);...
           0;...
           v_d*(X(1)-X(3))./norm([X(1)-X(3); X(2)-X(4)])*(norm([X(1)-X(3); X(2)-X(4)])>.01);...
           v_d*(X(2)-X(4))./norm([X(1)-X(3); X(2)-X(4)])*(norm([X(1)-X(3); X(2)-X(4)])>.01)];

Note that norm([X(1)-X(3); X(2)-X(4)]) just gives you the magnitude of the vector between the animals (e.g. the absolute distance).
The weird line that I put in the function handle ad the end of each line, *(norm([X(1)-X(3); X(2)-X(4)])>.01)] sets the system to be identically zero if our terminal condition is met. This is a hack! If the dog gets too close, we begin dividing by a small number and things go chaotic.
Normally, we might try a shooting method, but our initial conditions are well-specified.
Now just call ode45:
[tout, xout] = ode45(f,[0 T],x0);

To compute the distance between the animals, it is simple:
delta = sqrt((xout(:,1)-xout(:,3)).^2+(xout(:,2)-xout(:,4)).^2);

