Introductory Programming Fall 2005 For today you should have 1) turned in Evaluation 3 if you haven't Evaluation 4 will be next Tuesday Evaluation 3 Notes ------------------ 1) decide which variables are vectors and which are scalars 2) keep track of what's a vector and what's a scalar (exciting new error messages!) 3) we've seen two ways to build up a vector a) initialize using zeros, then set the elements one at a time b) accumulate the elements using [ ] operator We used (b) as a stepping-stone, but you should probably forget all about it now. 4) think of a loop as having three parts: before, during and after "during" in this case means once per iteration Euler's method -------------- v(t + dt) = v(t) + dv % this is just a definition of dv p(t + dt) = p(t) + dp % same here, no actual physics dv / dt = a(t) % this is the definition of acceleration dp / dt = v(t) % this is the definition of velocity So far I haven't told you much. Now imagine that I give you a; that is a(t) for all t. And I tell you v(0) and p(0). Your job is to estimate v(t) and p(t) for all t from 0 to 10.0 Two steps 1) approximate by replacing infinitesimals (dt, dv, and dp) with finite (but small) differences delta t, delta v, delta p. Why is this only approximate? 2) express the computation in MATLAB by using scalars for the finite differences, and vectors to represent the functions. Problem: a, v, and p are functions of time, and time is a continuous value (floating-point number) But the indices of a vector have to be integers. Solution: choose dt and divide the time line into numbered (discrete) values. Use i as an index for the vectors t, a, v, and p. Plot v and p versus t.