% EulerDriver.m % This is a driver that inputs the appropriate % initial conditions and step size for using the % function Euler.m to numerically solve the IVP given by % y' = f(t,y) y(t0)=y0 % Note that the user must input the name of the function % to be used to obtain function values for f(t,y) % Clear the workspace clear % Set initial conditions t0 = 0; y0 = 0; % Set step size and number of steps taken h = 0.1; M = 10; % name of the function containing the right-hand % side of the ode. %NOTE: USER MUST EDIT THE FOLLOWING!!!! name = 'h5num3'; % call Euler.m [t_vec,y_vec] = Euler(name,h,M,t0,y0); % t_vec is the vector of t-values from the step % size given by h. % y_vec is the corresponding approximations for the % solution to the ivp. We can plot the linear interpolant % of the approx. solution values along with the true solution % to compare. t=[t0:h/10:t0 + M*h]; % gives us a fine set of grid % points for the plot TrueSoln_vec = (t.*exp(3*t)-0.2*exp(3*t))/5+exp(-2*t)/25; figure(1) plot(t,TrueSoln_vec,'r-',t_vec,y_vec,'b*'); legend('True Solution','Euler, h = 0.1'); title('Homework 5, Number 3') xlabel('t'); ylabel('y(t)');