Homework #10
CS 107 - Introduction to Scientific Computation
Homework #10

Due: Wednesday 11/6 at the beginning of class
Note: The grading system will check return values only to see that results closely approximate correct results.  Grading for plotting will be done separately and manually.

1. Miniature Golf Simulation:  Imagine a 1 meter by 1 meter miniature golf green where

Create a function simGolf that takes as input:

and returns as output:

To simulate a bounce, do not merely reverse velocity, but also reflect the motion, such that the distance just traveled beyond a wall is reflected back as well.  For example, suppose you find that the y value is now 1.1.  This overshoots the wall by .1.  So the new reflected y value will now be 1 - .1 = .9. 

Within your simulation loop, the structure should be:

% change simulation value as if no walls exist
% in each case where a ball has gone beyond wall bounds, tally the bounce, reflect the motion, and reverse the velocity perpendicular to the wall
% add the new (x, y) point values to their respective result vectors.

2. Plotting a Single Golf Simulation Trajectory:  Taking the same input as simGolf, your function plotGolf will

For example, plotGolf(4, .3, .01) will return the integer 7 and plot this:

3. Plotting Many Golf Simulation Results: In function plotGolf2, you will take as input:

The output will be the matrix of simGolf bounce count return values you will be plotting.

The initial angle theta will be in the range (0, pi/2).  The minimum initial velocity will be 0.  Use linspace, these bounds, and the number of points to sample to create a meshgrid of initial velocities and angles. For each initial velocity and angle, perform the simGolf simulation, and store the first return value in a matrix.  Finally, create a plot of the values using

pcolor(<initial velocities>, <initial angles>, <matrix of return values>);

For example, plotGolf2(5, .01, 200) will return and plot this: