Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Const SOUND_SPEED = 330 'm/s
- Const BAT_SPEED = 20 'm/s
- Const TOTAL_DISTANCE = 4 'm
- Const SOUND_UPDATE = 1/1000000000 'How far sound will move before updating
- '(SOUND_UPDATE / SOUND_SPEED) is how long it takes for sound to move over a given distance
- 'The whole formula is how far the bat will move in that time
- Const BAT_MOVEMENT = BAT_SPEED / (1 / (SOUND_UPDATE / SOUND_SPEED))
- Print "The soundwave travels at "+Str(SOUND_SPEED)+"m/s"
- Print "The bat travels at "+Str(BAT_SPEED)+"m/s"
- Print "The bat will move "+Str(BAT_MOVEMENT)+"m in the same amount of time sound will"
- Print "move "+Str(SOUND_UPDATE)+!"m\n"
- Dim as Double Distance = TOTAL_DISTANCE 'How far away the two are from each other
- Dim as Double BatDistance = 0 'How far the bat has moved
- Dim as Double EndTime, StartTime = Timer 'For checking how long the calc took
- Do
- Distance -= SOUND_UPDATE 'Move the soundwave closer to the bat
- Distance -= BAT_MOVEMENT 'Simulate how far the bat will move in that timeframe
- BatDistance += BAT_MOVEMENT 'Update total distance bat has moved
- 'Print Distance, BatDistance, SOUND_UPDATE
- Loop Until Distance < SOUND_UPDATE 'Don't go into negative error
- EndTime = Timer
- Print "The bat moved "+Str(BatDistance)+"m in the amount of time it took the soundwave"
- Print "to get back to it."
- Print !"\nError of "+Str(Distance)+"m in final answer"
- Print !"\n"+Str(EndTime-StartTime)+"s to complete calculation"
- Sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement