function w = Euler %MATLAB routine for visualizing Euler's method %Created by Winfried Just, department of Mathematics, Ohio University %Last modified: February 6, 2003 syms t y disp(' ') input('Enter the right-hand side of the differential equation. \n'); f = ans disp(' ') input('Enter the given solution of the boundary value problem. \n'); g = ans disp(' ') input('Enter the value of a. \n'); a = ans disp(' ') input('Enter the value of y(a). \n'); ya = ans disp(' ') input('Enter the argument b for which you want to find y(b). \n'); b = ans while 0 < 1 disp(' ') input('Enter the value of Delta t or Ctrl^C to quit. \n'); dt = ans y0 = ya; t0 = a; hold off ezplot(g, [a - 0.5, b + 0.5]) hold on while t0 + 0.0000000000001 < b t1 = t0 + dt; y1 = double(subs(f, [t y], [t0 y0])*dt + y0); x = t0:dt/50:t1; plot(x, (y1 - y0)*(x - t0)/(t1 - t0) + y0) t0 = t1; y0 = y1; end error = subs(g, t, b) - y1 end