% % HW #1, problem 1.7.1 % % Solve an ordinary differential equation using Euler's method % % Jon Collis % 15 January 2009 % % Just make sure we don't have extra stuff confusing things clear; t(1) = 0; % gonna save time and y values here, though don't have to y(1) = 2; h = 0.001; % This is the grid spacing tmax = 2; % maximum time in seconds imax = tmax/h; for k=1:imax t(k+1) = t(k) + h; y(k+1) = y(k) + h*(2*y(k)-2*t(k)^2-3); end 'Our solution' y(end) % Analytic solution tt = 2; 'Analytic solution' tt*tt + tt + 2