%% Lecture 5 fun % % Last week. % % More throughts on Gauss, and practice with functions and % variables in functions. % % This week. Reprise of quiz 2, % code traces. % % a) Taylor Series expansion, and linear interpolation. % % b) Simulating time varying functions? % % c) Functions with multiple outputs. % In many physical systems, the quantity of interest is something that % varies with time (such as the position of an object, the temperature of a % surface). Let's call this function "f". The goal of good engineering % is often to *predict* what value "f" will have in the future. % Sometimes this can be done analytically, and classes in control theory, % electrical and mechanical engineering often explore systems which can % be mathematically solved. % % Computation tools are often used if the analytic version can't be % solved. Computation rests on "doing simple things over and over % again". % % Today we will explore a simple physical phenomena, and see what all % needs to be done to simulated it. % % So let us consider some function x(t). To make this concrete, suppose % we care about the x-position of a mass attached to a spring: %| |===| %|wwwwwwwww| | %| |===| %____________________________ % % ----x---- % x(t) will be the position x at time t. % Now if we are going to update x, we need to understand how it changes. % % "Hooke's" law from physics, says that a spring, exerts a force F % following the rule: % % F = -k * distension % % where distension is how long the spring is extended. % and "k" is how strong the spring is ( % F = m * a % dv/dt = a; % dx/dt = v % x is the value we are interested in. % Now, the key concept in simulation is "Taylor Series Expansion". % Who's heard of this? It really is that big of a deal. % It says that *any* smooth function f(t) can be approximated near some % time t as: % x(t+dt) ~= x(t) + dx/dt * dt + d^2x/dt^2 * dt^2 + .... % % Then, the trick is to set dt small enough that dt^2 is very close to % zero. % so how do we apply this to our spring? % How should we organize our program? % we'll need an initialization step? % what do we need to specify? % we'll need an update function % what do we need to update? % we'll need some visualization % what do we want to visualize? % Can we make the visualization pretty?