Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An important part of computer programming is simulation. In this program we\'re

ID: 658269 • Letter: A

Question

An important part of computer programming is simulation. In this program we're going to perform about the simplest possible simulation: Sim Bouncy Ball. The program will simulate a ball bouncing on a hard surface.

Recall that:

a) The acceleration due to gravity "g" is 9.8 ms-2 in a downward direction.

b) The "coefficient of restitution" is defined as the ratio of an object's speed just after it bounces/the object's speed just before it bounces (for obvious reasons, it is a number between 0 and 1).

1) Create variables to hold the current height and velocity of the ball, coefficient of restitution, simulation start time, simulation end time and the current simulation time.

2) Initialise the height, velocity and starting simulation time to 0secs.

3) Choose a small time step 'dt' which will be one "cycle" of our iteration.

4) In each time step (until we reach the end time for our simulation)

    a) add dt*g to the velocity.

    b) add dt*v to the height.

    c) add dt to the current time.

    d) if the height is less than zero and the ball's velocity "down" then multiply the velocity by the negative of the coefficient of restitution (to make it instantaneously bounce back up).

    e) print out the ball's current height and the simulation current time at each step.

Hint: Be careful with your signs - be sure that your velocity, acceleration and height all have matching orientations.

i) Run your simulation for height against time for h= 10, initial velocity= 0, coefficient of restitution 0.9 starting at 0 seconds and end time 10 seconds. Choose a sensible time-step. a graph of height versus time - either using maple (as described last week), or using any other graph plotting package you know.

ii) What is the effect of changing the time step to make it longer or shorter?

iii) What are the trade-offs involved in running the simulation with a long and a short time step.

iv) Using maple and the plotting routines you've previously developed in question one, plot the graph for the simulation with two smaller values of coefficient of restitution.

v) A small but constant error is introduced by the fact that the height is changed AFTER the velocity. Describe the nature of this error. Suggest a way to correct this. (Note that changing the height BEFORE the velocity merely changes the error it

Explanation / Answer

#include<stdio.h>

#include<iostream.h>

#include<graphics.h>

#include<conio.h>

#include<stdlib.h>

#include<dos.h>

int n = 200,x = 50, y = 50, r=30;

int main()

{float currHeight=0, velocity=0, coeff_Restt, Sim_strt=0, Sim_end, Sim_Curr;

float g=9.8,dt;

printf(

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote