Introductory Programming Fall 2006 The result of many numerical simulations is a table of values that approximate a function we are interested in. For example, the output of ode45 is a vector of time values, T, and a vector or matrix of variables, M. Each column of M is like a function of time, but we only know the value at some points. To estimate the value of this "function" at other points, we can interpolate. MATLAB provides several interpolation functions; the simplest to use is interp1. For example, let's say we have a vector of times from 0:2 pi T = linspace(0, 2*pi) And then we evaluate the sin function at those times Y = sin(t) We could use interp1 to estimate the sin(0.1) interp1(T, Y, 0.1) How close is the result to the correct answer (relative error, please)? How about if we use a cubic interpolation function (instead of the default, which is 'linear')? interp1(T, Y, 0.1, 'cubic') interp1(T, Y, 0.1, 'spline') Field mice ---------- Read the field mouse question on the next page. Use interp1 and ode45 to solve this problem. Note: think about how many functions to write, how to name them, and what input/output variables they should take. How much does it change the result if we run with different kinds of interpolation? Baseball -------- You might remember that we saw two versions of baseball. 0) One of them used odeset to stop the simulation when the ball hit the ground. 1) One of them allowed the ball to fall through the ground and then went back later to see where it hit. You can download both of them from the class web page; they are named baseball.m and baseball1.m, respectively. Try calling baseball and baseball1 with the same arguments. How big is the difference? The problem with baseball1.m is that it reports the distance of the first point whose y-coordinate is negative, which means that it goes too far. What we should really do is interpolate between the last positive point and the first negative point. Your mission: Use interp1 to fix baseball1 and see if it becomes more consistent with baseball.