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