Last updated December 5, 2017. Computational Project 5 due: 12/07/2017, beginning of class 1. You are playing a game of angry birds. In order to hit the pig you need to first shoot your bird through a gap in a pillar. This problem focuses on this first step; hitting the pig is question 2. The equations governing the trajectory of a bird after launch are dy 2 2 = mg c (1) m d2 x dx 2 2 = c (2) where x is horizontal position, y is altitude, m is the bird s mass = 1.5 kg, g is the acceleration of gravity = 9.8 m/s 2, and c is a drag coefficient = 0.5 kg m 1. The 1
launching coordinate is at zero elevation, zero distance, i.e., y(0) = x(0) = 0. The bird is launched with a speed equal to v 0 at angle θ (in degrees) relative to the ground. Thus the initial x and y velocities are 2πθ v y (t = 0) = v 0 sin v x (t = 0) = v 0 cos 360 ) ( 2πθ 360 From trial and error, you have determined that the most plausible way of beating this level is to fly the bird through the gap exactly at the apex of its trajectory. Use this information to find v 0 and θ using the shooting method. The maximum value of θ allowed is 80 and the maximum speed is v 0 = 10. The wall is located at x = 0.9 m, and the gap is between 1.25 < y < 1.5 m. (a) First, write MATLAB code that solves for the bird s trajectory. Use MATLAB s internal ODE solvers for this part. Your code should make a plot of the bird s trajectory, y(t) vs x(t), for y(t) > 0. Set the plot range to be axis([0 5 0 3]). Experiment with different values of θ, m, c, and v 0 to convince yourself that the code is working properly. (b) Compute the vertical height (y(t w )) at the time (t w ) at which the bird will be passing through the wall, (i.e., when x(t w ) = 0.9). Since MATLAB will not necessarily include this exact point in its solution to the ODEs, you will need to use interpolation to arrive at a precise estimate of y(t w ), or force MATLAB to return a finely resolved solution vector using tspan. Also compute v y (t w ). (c) Transform your code from parts (a) and (b) into a function that takes as input z = [v 0, θ] and outputs a vector f containing two elements: the difference between the target height and computed height at t w and the difference between the target vertical velocity and computed vertical velocity at t w. (d) Use the function from part (c) to find reasonable values of v 0 and θ, and plot your solution from t = 0 to t = t w. Some experimentation may be required. You may refer to HW03, problem # 5 for use of the fsolve routine. Alternatively, the fminsearch routine can work well for this problem (it only requires that you modify part (d) such that the function returns a scalar norm of the output vector, f ). You may find MATLAB displaying some annoying warning messages encountered if/when y(t) < 0. Since we are not interested in this part of the solution, you can surppress these using warning( off, MATLAB:ode45:IntegrationTolNotMet ) 2
2. The pig is located at x = 4 m, and the parabolic trajectory computed in part 1 will pass through the gap in the wall but will not hit the pig. Fortunately, you have a yellow bird which you can activate with a boost of acceleration in the x direction. The equations governing the trajectory of a bird including this boost are dy 2 2 = mg c (3) m d2 x dx 2 2 = c + u(t, t b )b (4) (5) where b is a boost of force = 380 kg m s 2 activated at time t b. u(t, t b ) is a step function, whose value is 0 for t < t b and 1 for t t b. The pig will be hit if the horizontal distance traveled when the bird impacts the ground is at 4 ± 0.1 m. Use the shooting method to find the value of t b such that the bird hits the pig. (a) First, write MATLAB code that solves for the bird s trajectory using MATLAB s internal ODE solvers. For the step function, use stepfun. Your code should also make a plot of the bird s trajectory, y(t) vs x(t), for y(t) > 0. (b) Compute the horizontal d traveled between the launch point and impact, where impact occurs when y(t) = 0 for t > 0. (c) Transform your code from parts (a) and (b) into function that takes as input a value of the boost time, t b, and outputs the difference between d and the pig s location. (d) Use a numerical root finding method (either written yourself, provided in class, or use MATLAB internal functions) to calculate and display the desired boost time such that the pig is hit. 3
3. In the next level, we are introduced to the exploding birds, which have a fuse to automaticlaly detonate in 3 s. The goal is to detonate the bomb exactly at the time it impacts the beam holding up the pig, with a maximum hang time in the air. Otherwise, it will get wet and diffuse. In other words, it is desired to find the initial vertical velocity such that y(3) = 0. For this problem we will ignore drag in the x-direction and directly solve the following ODE in the y-direction using the finite differences method 2 = mg c dy (6) subject to y(0) = 0, y(3) = 0. aerodynamic, c = 0.75 kg s 1. These birds are lighter, m = 0.5 kg, but not as (a) Include the following written (or typed) steps with the hard copy of your solution. Begin by sketching a picture of the discretized problem using 11 evenly spaced nodes ( t = 0.3 s). Next, write down the finite difference representations of the derivative terms in the governing equation; use expressions that 4
are second order accurate in t. Then use these to derive a discrete governing equation. Apply this discrete governing equation at each of the internal nodes of your domain (or at least enough to see the pattern) you should end up with 9 equations. Incorporate the boundary conditions into these equations. (b) Use MATLAB to solve the resulting system of linear equations for the vertical trajectory, y(t), and plot the solution. (c) From the computed trajectory, calculate and display the initial vertical velocity, v y (0), required to keep the bird a loft for 3 s. Is this solution approach feasible, given that the maximum initial speed is 10 m/s, and maximum angle is 80? If not, approximately what is the longest fuse time that would be feasible? 5