%Gerardo

function SlopeField

%% Section 2.2: 

%dy/dx=x^2/(1-y^2)

Nx=100; Ny=100;
x_0=-4; x_1=4;
y_0=-4; y_1=4;

dx=(x_1-x_0)/Nx; 
dy=(y_1-y_0)/Ny; 

f=zeros(Nx,Ny,2);
g=zeros(Nx,Ny);
x_axis=zeros(Nx,1);
y_axis=zeros(Ny,1);
for iy=1:Ny
    y=y_0+dy*(iy-1);
    y_axis(iy,1)=y;
    for ix=1:Nx
        x=x_0+dx*(ix-1);
        x_axis(ix,1)=x;
        f(ix,iy,1) = 1-y^2;
        f(ix,iy,2) = x^2;
        
        g(ix,iy) = x^3+y^3-3*y;
    end
end

clf
figure(1)
hold on
contour(x_axis,y_axis,transpose(g),100)
%stop

Feq=5;
% clf
% figure(1)
hold on
quiver(x_axis(1:Feq:Nx),y_axis(1:Feq:Ny),transpose(f(1:Feq:Nx,1:Feq:Ny,1)),transpose(f(1:Feq:Nx,1:Feq:Ny,2)),1)
plot(x_axis,y_axis*0)
plot(x_axis*0,y_axis)
axis([x_0 x_1 y_0 y_1])
axis on
stop


