% This program will performs Euler's method, given a differential equation % saved in a file called diff_eq.m. Set up diff_eq.m just as you would if % you were using MatLab's ode45 command. We call euler.m just as we would % call ode45. % Inputs: % % file_name - This is a string that contains the name of the M-File that % holds the differential equation we want to evaluate. % tvalues - A vector of the form [tstart tfinish] that contains our starting % and stopping times. % y0 - Our initial condition, y0 = y(tstart). % N - The number of iterations we would like to perform % Outputs: % % t - The vector of time values that was used. % y - The vector of y values that contains the solution. function [t y]=euler(file_name,tvalues,y0,N) % You setup your initial conditions here. for i=2:N+1 % Use i as our index, it goes from 2 to N+1 temp_string=[file_name,'(t(i-1),y(i-1))']; % Setup the string that contains the function call we want to evaluate. f=eval(temp_string); % Evaluate the function call. % Finish Euler's Method here. end