
    clc, clear, close all
       % Clear the command window screen, all the variables
       % and close all windows
	
	   % Input your slope function f(x,y) (as a string), 
       % i.e. for the DE y'(x)=f(x,y).  In this linear DE example, 
       % f(x,y) = 1-3x+y but you can enter whatever function you want.
	   % So we would enter:  f = '1-3.*x+y';
    f='1-3.*x+y';
       % use "3." instead of "3" (which would cause an error) for
       % scalar multiplication.
       
    xmin = -1; 
    xmax = 1;
    ymin = -1; 
    ymax = 1;
       
    SlopeField(xmin,xmax,ymin,ymax,f)
       % Draw the slope field in the 
       % region xmin<=x<=xmax, ymin<=y<=ymax for dy/dx = f(x,y)
	
	hold on
       % the "hold on" command lets us add more plots to the display
       % of the first plot, e.g. the slope field in this script, rather
       % than creating different displays for each plot.
    
	% Use Euler method to solve the IVP on 
    % the interval [x0,xmax] with n subintervals : 
	% dy/dx = f(x,y)
	% y(x0) = y0
	x0 = 0; 
    y0 = 0;
    b=1;
    n = 5;
    
     % Use Euler Method to Solve, then add scatter plot:
	[xE yE]=Eulers(x0,y0,b,n,f);
	scatter(xE,yE,20,'blue','filled');
    
    % Use Improved Euler Method to solve 
	[xI yI]=Improved_Eulers(x0,y0,b,n,f);
	scatter(xI,yI,20,'red','filled');
    
     % Use Runge Kutta method to solve
	[xR yR]=Runge_Kutta(x0,y0,b,n,f);
	scatter(xR,yR,20,'black','filled');
       
    sol='2+3.*x-2.*exp(x)';
     % exact solution in our example
    sol = str2func(['@(x)',sol]);

    Z=0:.02:1;  % x-coords from 0 to 1, partition width .02.
    W=sol(Z);   % y-coords for exact solution
    plot(Z,W,'color','black','LineWidth',1);

	
	xlabel('x');ylabel('y')
	legend('Slope Field','Euler','Improved Euler','Runge Kutta','Exact')
    title(['dy/dx = ' f])
    