function [x, y]= myeuler(f, xinit, yinit, b, n) % use help myeuler to read this info in MATLAB % % % function [x, y]= myeuler(f, xinit, yinit, b, n) % % Euler approximation for inital value problem % dy/dx = f(x, y), y(xinit) = yinit. % Approximations y(1),...,y(n+1) are calculated at % the n+1 points x(1),...,x(n+1) in the interval % [xinit,b]. The right-hand side of the differential % equation is defined as an inline function f. % Calculation of h from xinit, b, n h= (b - xinit)/n; % initialize x and y as length n+1 column vectors. x = zeros(n+1, 1); y = zeros(n+1, 1); % Calculate the points x(i) and the corresponding % approximate values y(i) from the Euler Method formula. x(1) = xinit; y(1) = yinit; for i=1:n x(i+1) = x(i) + h; y(i+1) = y(i) + h * f(x(i), y(i)); end