Euler.m:function [t,y] = euler(f,tspan,y0,N)% Solves the IVP y’ = f(t,y), y(t0) = y0 in the time interval tspan = [t0,tf]% using Euler’s method with N time steps.% Input:%f= name of inline function or function M-file that evaluates the ODE%(if not an inline function,use: euler(@f,tspan,y0,N))%For a system,
Euler.m:function [t,y] = euler(f,tspan,y0,N)% Solves the IVP y’ = f(t,y), y(t0) = y0 in the time interval tspan = [t0,tf]% using Euler’s method with N time steps.% Input:%f= name of inline function or function M-file that evaluates the ODE%(if not an inline function,use: euler(@f,tspan,y0,N))%For a system, the f must be given as column vector.%tspan = [t0, tf] where t0 = initial time value and tf = final time value%y0= initial value of the dependent variable. If solving a system,%initial conditions must be given as a vector.%N= number of steps used.% Output:% t = vector of time values where the solution was computed% y = vector of computed solution values.m = length(y0);t0 = tspan(1);tf = tspan(2);h = (tf-t0)/N;% evaluate the time step sizet = linspace(t0,tf,N+1);% create the vector of t valuesy = zeros(m,N+1);% allocate memory for the output yy(:,1) = y0′;% set initial conditionfor n=1:Ny(:,n+1) = y(:,n) + h*f(t(n),y(:,n));% implement Euler’s methodendt = t’; y = y’;% change t and y from row to column vectorsenddfeld8.m:function output = dfield8(action,input1,input2,input3)% dfield8is an interactive tool for studying single first order%differential equations.When dfield8 is executed, a dfield8 Setup%window is opened.The user may enter the differential%equation and specify a display window using the interactive%controls in the Setup window.%%When the Proceed button is pressed on the Setup window, the DF%Display window is opened.At first this window displays a%direction line field for the differential equation.When the%mouse button is depressed in the dfield8 Display window, the%solution to the differential equation with that initial%condition is calculated and plotted.%%Other options are available in the Options menu.These are%fairly self explanatory.The Settings option allows the user%to change several parameters.Included here are the%possibilities of using a vector field instead of the default%line field, and of changing the number of field points computed%and displayed.