CoCalc Shared FilesPOW / POW Spring 2019 #1 / POW.ipynbOpen in CoCalc with one click!
Author: Peter Francis
Views : 10
In [74]:
### Specify the initial conditions... p = .1 # x position of dog (0 <= p <= 1) r = 40 # speed of dog # ...and we'll do the rest! t_e = sqrt(p^2+1)/r # expected catch time x = copy(p) y = 1 t = 0 d = 0.0001 dogPoints = [(x,y)] for i in [0..(1/d)]: x_1 = x + (r*d*(t-x)/(sqrt((t-x)^2+y^2))) y_1 = y + (r*d*(-y)/(sqrt((t-x)^2+y^2))) t = t + d dogPoints = dogPoints + [(x_1,y_1)] x = copy(x_1) y = copy(y_1) if sqrt(y^2+(x-t)^2) <= .001: stop = x break show(point(dogPoints) + plot(1, (x,0,1)) + point((t_e,0), color='red', marker="D"), xmin=0, xmax=1, ymin=0, ymax=1) print "p=",p print "r=",r print "t_{expected}=",t_e print "t_{computer}=",stop
p= 0.100000000000000 r= 40 t_{expected}= 0.0251246890528022 t_{computer}= 0.0250561405535776