function y_2 = odeStep_midPt(x_1,y_1,h,deriv) %y_2 = odeStep_midPt(x_1,y_1,h,deriv); % A self-starting, simple, single mid point (Runge-Kutta 2nd-order) % 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_1+h) % (c) 2007 Curt A. L. Szuberla % University of Alaska Fairbanks, all rights reserved % ver 1.0 % 21 December 2007 % implementation of standard Runge-Kutta 2nd-order formula k_1 = h * deriv(x_1,y_1); % use slope at start to estimate k_2 = h * deriv(x_1 + h/2 , y_1 + k_1/2); % final point then take that y_2 = y_1 + k_2; % information to go half way and % get a new slope for estimating % final point return