1
$\begingroup$

A dog in the coordinate system starts from the origin along the x-axis with vk=1m/s speed. The owner starts from the (0,1) point running towards the direction of the dog with vg=2m/s speed.Show the path of the dog and owner(blue and red) on the t=[0,0.51] interval.

This is the graph that i need to get: enter image description here

Here is my take on it,but for some reason the path of the owner won't reach the dog on t=[0,0.51] in my case.

{kutyax, kutyay, gazdaq, gazdaz} = 
 NDSolveValue[{x'[t] == 1, y'[t] == 0, 
   z'[t] == 2*(x[t] - z[t])/Sqrt[(x[t] - z[t])^2 + (y[t] - q[t])^2], 
   q'[t] == 2*(y[t] - q[t])/Sqrt[(x[t] - z[t])^2 + (y[t] - q[t])^2], 
   x[0] == 0, y[0] == 0, z[0] == 0, q[0] == 1}, {x, y, z, q}, {t, 0, 
   0.51}]
Show[ParametricPlot[{kutyax[t], kutyay[t]}, {t, 0, 0.51}, 
  PlotStyle -> Blue], 
 ParametricPlot[{gazdaq[t], gazdaz[t]}, {t, 0, 0.51}, 
  PlotStyle -> Red]]

And here is my graph: enter image description here

$\endgroup$
1
5
$\begingroup$

Your expectation dog reaches owner at t=.51 seems to be wrong!

I modified NDSolve with a WhenEvent

{kutyax, kutyay, gazdaq, gazdaz} =NDSolveValue[{x'[t] == 1, y'[t] == 0,z'[t] == 2*(x[t] - z[t])/Sqrt[(x[t] - z[t])^2 + (y[t] - q[t])^2], q'[t] == 2*(y[t] - q[t])/Sqrt[(x[t] - z[t])^2 + (y[t] - q[t])^2],x[0] == 0, y[0] == 0, z[0] == 0, q[0] == 1
, WhenEvent[(x[t] - z[t])^2 + (y[t] - q[t])^2 == 0.0001 ,  "StopIntegration"]}, {x, y, z, q}, {t, 0, 1}]
tsim = kutyax["Domain"][[1, 2]]  
(*0.656669*)

dog reaches owner at t=.66!

Show[{ParametricPlot[{kutyax[t], kutyay[t]}, {t, 0, tsim}, PlotStyle -> Blue],ParametricPlot[{gazdaq[t], gazdaz[t]}, {t, 0, tsim}, PlotStyle -> Red]}, PlotRange-> All]  

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.