Matelab and latex professional report
CS 111 - Introduction to Computational Science Fall 2017
Homework 2
The goal of this exercise is to simulate the motion of a ball bouncing off the walls of a closed container, as described in class. Denote as (x,y) the ball coordinates and as (vx,vy) its velocity. Suppose at time t = 0 the ball is located at (x0,y0) and has velocity (v0x,v
0 y). The main force acting
on the ball is the gravitational force ( ~Fgrav = m~g) so that the motion of the ball is described by the system of second-order differential equations
d2x
dt2 = 0
d2y
dt2 = −g
(1)
with the initial conditions x(0) = x0,
dx
dt (0) = v0x
y(0) = y0, dy
dt (0) = v0y
(2)
When the ball interacts with the walls, friction forces apply. In particular, the normal velocity is damped by a factor α and the tangential velocity is damped by a factor β.
Write a code to simulate the problem above. Convert system of equations (1) into a system of first-order differential equations and use the explicit trapezoidal method to solve it. To test your code set the size of the closed container to be [0, 1] × [0, 1], the ball radius r = .05 m, the initial location of the ball at (x0,y0) = (.1, .7) m, its initial velocity to (v0x,v
0 y) = (3., 1.) m/s, α = .8, β = .9
and g = 9.81 m/s2. Find the location of the ball and its velocity at time t = 0.931 using time-steps ∆t = 0.02, 0.01, 0.005, 0.0025, 0.00125 and 0.000625, compare with the exact values obtained using MATLAB code bouncing_ball_exact.m and calculate the order of accuracy.
Take snapshots of your simulations at times t = 0.2, 1.0 and 2.5 for ∆t = 0.01. What to turn in: your code and a professional report should be uploaded to Gauchospace. Your
report should contain a description of the problem, explanations of the overall approach to solving the problem and relevant numerical methods (e.g. transition from high-order ODEs to a system of first-order ODEs, trapezoidal method for systems of ODEs, approach to model interactions between the ball and the walls, etc), and a discussion of the results you obtain. Do not copy your codes into your report, they should be uploaded separately. Upload all additional MATLAB functions (e.g. draw_ball.m) necessary to run your code.
1