% Usage: y = midpointstep(f,t,x,h) % One step of the midpoint method for initial value problems % % Input: % f - Matlab inline function f(t,y) % t - initial time % x - initial condition % h - stepsize % % Output: % y - computed solution at t+h % % Examples: % y=midpointstep(@myfunc,0,1,0.1); here 'myfunc' is a user-defined function in M-file % y=midpointstep(inline('sin(y*t)','t','y'),0,1,0.1); % f=inline('sin(y(1))-cos(y(2))','t','y'); % y=midpointstep(f,0,1,0.1); function y = midpointstep(f,tx,h) halfh = h/2; z = x + halfh * f(t,x); y = x + h * f(t+halfh,z);