function y_2 = odeStep_euler(x_1,y_1,h,deriv) %y_2 = odeStep_euler(x_1,y_1,h,deriv); % A self-starting, simple, single Euler step function % x_1 --> initial independent variable (scalar, typically time) % y_1 --> initial dependent variable (vector) % h --> step size in x %deriv --> function handle for derivative function (may be annonymous call % if derivatives are functions of parameters other than x & y) % y_2 <== final dependent variable; i.e., y(x_n+h) % (c) 2007, 2008 Curt A. L. Szuberla % University of Alaska Fairbanks, all rights reserved % ver 1.01 % 2 February 2008 % implementation of standard Euler formula k_1 = h * deriv(x_1,y_1); % use slope at start y_2 = y_1 + k_1; % to estimate final point % some things to note here: % the function to take a single Euler-type step has 4 inputs and delivers % one output (we don't need to output x_2, since it's simply x_1 + h) % notice how the function handle to our derivative function is passed in as % input WITHOUT arguments, but when it is called in the function it is % called with the two generic input arguments, the independent variable % (x_n) and the independent variable (y_n) % % we'll soon see that the Euler method is too error prone for oscillating % sysems and taht a simple modification will do much better -- but the way % we've constructed this function lends itself to the improved versions, % since they will take EXACTLY the same input arguments and deliver the % same output return