Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Const SOUND_SPEED    = 330   'm/s
  2. Const BAT_SPEED      = 20    'm/s
  3. Const TOTAL_DISTANCE = 4     'm
  4. Const SOUND_UPDATE   = 1/1000000000 'How far sound will move before updating
  5. '(SOUND_UPDATE / SOUND_SPEED) is how long it takes for sound to move over a given distance
  6. 'The whole formula is how far the bat will move in that time
  7. Const BAT_MOVEMENT = BAT_SPEED / (1 / (SOUND_UPDATE / SOUND_SPEED))
  8.  
  9. Print "The soundwave travels at "+Str(SOUND_SPEED)+"m/s"
  10. Print "The bat travels at "+Str(BAT_SPEED)+"m/s"
  11. Print "The bat will move "+Str(BAT_MOVEMENT)+"m in the same amount of time sound will"
  12. Print "move "+Str(SOUND_UPDATE)+!"m\n"
  13.  
  14. Dim as Double Distance = TOTAL_DISTANCE  'How far away the two are from each other
  15. Dim as Double BatDistance = 0            'How far the bat has moved
  16. Dim as Double EndTime, StartTime = Timer 'For checking how long the calc took
  17. Do
  18.     Distance -= SOUND_UPDATE    'Move the soundwave closer to the bat
  19.     Distance -= BAT_MOVEMENT    'Simulate how far the bat will move in that timeframe
  20.     BatDistance += BAT_MOVEMENT 'Update total distance bat has moved
  21.     'Print Distance, BatDistance, SOUND_UPDATE
  22. Loop Until Distance < SOUND_UPDATE   'Don't go into negative error
  23. EndTime = Timer
  24.  
  25. Print "The bat moved "+Str(BatDistance)+"m in the amount of time it took the soundwave"
  26. Print "to get back to it."
  27. Print !"\nError of "+Str(Distance)+"m in final answer"
  28.  
  29. Print !"\n"+Str(EndTime-StartTime)+"s to complete calculation"
  30. Sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement