12.07.2015 Views

Simple Nature - Light and Matter

Simple Nature - Light and Matter

Simple Nature - Light and Matter

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

But by increasing n to ten thous<strong>and</strong>, we get an answer that’s asclose as we need, given the limited accuracy of the raw data:>>> print(time2(1.0,10000)) # h, n0.44846664060793945A subtle point is that we changed y in line 9, <strong>and</strong> then on line10 we calculated v, which depends on y. Since y is only changingby a ten-thous<strong>and</strong>th of a meter with each step, you might thinkthis wouldn’t make much of a difference, <strong>and</strong> you’d be almost right,except for one small problem: if we swapped lines 9 <strong>and</strong> 10, thenthe very first time through the loop, we’d have v=0, which wouldproduce a division-by-zero error when we calculated dt! Actuallywhat would make the most sense would be to calculate the velocityat height y <strong>and</strong> the velocity at height y+dy (recalling that dy isnegative), average them together, <strong>and</strong> use that value of y to calculatethe best estimate of the velocity between those two points. Sincethe acceleration is constant in the present example, this modificationresults in a program that gives an exact result even for n=1:1 import math2 def time3(h,n):3 g=9.84 y=h5 v=06 dy = -h/n7 t=08 for i in range(n):9 y_old = y10 y = y+dy11 v_old = math.sqrt(2*g*(h-y_old))12 v = math.sqrt(2*g*(h-y))13 v_avg = -(v_old+v)/2.14 dt=dy/v_avg15 t=t+dt16 return t>>> print(time3(1.0,1)) # h, n0.45175395145262565Now we’re ready to attack a problem that challenged the bestminds of Europe back in the days when there were no computers.In 1696, the mathematician Johann Bernoulli posed the followingfamous question. Starting from rest, an object slides frictionlesslyover a curve joining the point (a, b) to the point (0, 0). Of all thepossible shapes that such a curve could have, which one gets theobject to its destination in the least possible time, <strong>and</strong> how muchSection 2.2 Numerical Techniques 93

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!