%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Computational Physics % FALL 2008 % % Instructor: Kevin H. Knuth % % % HW 3 % Numeric Integration % % The purpose of this homework set is to introduce you to the subtleties of % numeric integration while being conscious of both numerical errors and % speed. In addition, you will learn about function handles, which allow % you to write functions that take functions as arguments. % % % TURN IN: % m-files titled myTRAP.m and myQUAD.m % Report on methods and accuracy and errors as a function of spacing % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Problem by: Kevin H. Knuth % Created on: 09 February 2008 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PART 1 % Write a function myTRAP that integrates a function based on the % trapezoidal approximation. You may compare to the MATLAB function TRAPZ, % but cannot use TRAPZ.m. % % Usage: integral = myTRAP(funHANDLE, x) % Inputs: funHANDLE = function handle % x = array of x-coordinates % Outputs: integral = Integral over limits imposed by x % % % PART 2 % Write a function myQUAD that integrates a function based on the % Simpson approximation. You may compare to the MATLAB function QUAD, but % cannot use QUAD.m % Keep in mind that the number of evaluation points must be odd and that % there must at least be seven points. You may want to test for that! % % Usage: integral = myQUAD(funHANDLE, x) % Inputs: funHANDLE = function handle % x = array of x-coordinates % Outputs: integral = Integral over limits imposed by x % % % PART 3 % Write a report analyzing the motion of a falling raindrop. % % 1. Start with Newton's Laws and assume that the droplet experiences a % linear drag due to air resistance. That is: % F = -cv % where c is a constant. % Derive the equation for the velocity as a function of time. % % 2. Next derive the equation for the position as a function of time. % % 3. Then write a function velocity.m that takes three arguments: % the the current time t, initial time time to, the mass of the particle, % and the drag coefficient c and returns the velocity. % % 4. Now we will solve a more realistic problem. For a raindrop with % diameter d = 10e-4 meter, % and a drag coefficient of c = d * 1.55 * 10e-4 Ns/m^2, % use your solution to step 2 to compute how far the drop will fall % in 100 seconds after starting from rest. % % 5. Determine the appropriate number of time steps for the integration % and run the two integration algorithms myTRAP.m and myQUAD.m to % numerically compute the distance the raindrop will fall in 10 seconds % after starting from rest. Compare these results to your answer in % Step 4. % HINT: You will need to pass a function handle referring to velocity.m % however, you will want to fix the values of to and c. Consider % defining the anonymous function: % raindrop = @(t) velocity(t, to, m, c); % and pass it to myTRAP and myQUAD. % % 6. Make a plot of the difference between your numeric estimate and the % analytic estimate over an interesting range of time intervals. % % OPTIONAL. Make plots of the droplet's velocity and position over the % first 10 secs. How does the distance the droplet falls compare to a % particle in a vacuum? % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%