% the program takes the intial data y_0 at the initial time x_0 and % computes up to time x_final using timesteps of size dx. It creates % two vectors, x and y, which you can then plot against each other % plot(x,y) % % [x,y] = euler_step(y_0,x_0,x_final,dx) function [x,y] = euler_step(y_0,x_0,x_final,dx) % for dy/dx = f(y(x),x) % y(x+dx) ~ y(x) + dx y'(x) = y(x) + dx f(y(x),x) % number of steps to take n = ceil((x_final-x_0)/dx) + 1; % put initial data into vector x(1) = x_0; y(1) = y_0; for i=1:n-1 y(i+1) = y(i) + dx*F(y(i),x(i)); x(i+1) = x_0 + i*dx; end