% To run: type dirfield
% To change the problem solved, simply edit the
% function f(x,y)

function dirfield()
  clear all
  close all
  axis([-4 4 -4 4])
  X1 = linspace(-4,4,41); Y1 = linspace(-4,4,41);
  hold on
  % plot direction field
  df2@f,X1,Y1,'x','y','dirfield','r',0);
  hold on
  %figure
  % plot exact solution
  yex = exact(X1);
  plot(X1,yex,'g-')
  % plot initial condition
  y0 = -2; x0 = 0;
  plot(x0,y0,'kp')

  % define differential equation
   function yp = f(x,y)
  % warning: f must be vectorized, ie use x.^2 
    yp = 2*x./(y.*(1+x.^2));
   % yp = 2*y -3;
   
   % define exact solution 
      function ye = exact(x)
          ye = -sqrt(4+2*log(1+x.^2));
