%Gerardo

function Hw1

%% Section 1.1 problem 1

% Nx=30; Ny=30;
% x_0=0; x_1=2;
% y_0=0; y_1=3;
% 
% dx=(x_1-x_0)/Nx; 
% dy=(y_1-y_0)/Ny; 
% 
% f=zeros(Nx,Ny,2);
% 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;
%         f(ix,iy,2) = 3-2*y;
%     end
% end
% 
% clf
% figure(1)
% hold on
% quiver(x_axis,y_axis,transpose(f(:,:,1)),transpose(f(:,:,2)),2)
% axis([x_0 x_1 y_0 y_1])
% print('SlopeFieldSec1pt1Prob1','-depsc',figure(1))
% stop

%% Problem 1 Section 1.2

% Nx=30; Ny=30;
% x_a=0; x_b=2;
% y_a=4; y_b=6;
% 
% dx=(x_b-x_a)/Nx; 
% dy=(y_b-y_a)/Ny; 
% 
% f=zeros(Nx+1,Ny+1,2);
% x_axis=zeros(Nx+1,1);
% y_axis=zeros(Ny+1,1);
% for iy=1:Ny+1
%     y=y_a+dy*(iy-1);
%     y_axis(iy,1)=y;
%     for ix=1:Nx+1
%         x=x_a+dx*(ix-1);
%         x_axis(ix,1)=x;
%         f(ix,iy,1) = 1;
%         f(ix,iy,2) = 5-y;
%     end
% end
% 
% y_0=6;
% 
% sol=zeros(Nx+1,1);
% for ix=1:Nx+1
%     sol(ix,1)=5+(y_0-5)*exp(-x_axis(ix,1));
% end
% 
% hold on
% %clf
% figure(1)
% hold on
% quiver(x_axis,y_axis,transpose(f(:,:,1)),transpose(f(:,:,2)),1)
% plot(x_axis,sol,'r -','LineWidth',2)
% axis([x_a x_b y_a y_b])
% print('SlopeFieldSec1pt2Prob1a','-depsc',figure(1))
% stop

%

% Nx=30; Ny=30;
% x_a=0; x_b=2;
% y_a=0; y_b=5;
% 
% dx=(x_b-x_a)/Nx; 
% dy=(y_b-y_a)/Ny; 
% 
% f=zeros(Nx+1,Ny+1,2);
% x_axis=zeros(Nx+1,1);
% y_axis=zeros(Ny+1,1);
% for iy=1:Ny+1
%     y=y_a+dy*(iy-1);
%     y_axis(iy,1)=y;
%     for ix=1:Nx+1
%         x=x_a+dx*(ix-1);
%         x_axis(ix,1)=x;
%         f(ix,iy,1) = 1;
%         f(ix,iy,2) = 5-2*y;
%     end
% end
% 
% y_0=5;
% 
% sol=zeros(Nx+1,1);
% for ix=1:Nx+1
%     sol(ix,1)=5/2+(y_0-5/2)*exp(-2*x_axis(ix,1));
% end
% 
% hold on
% %clf
% figure(1)
% hold on
% quiver(x_axis,y_axis,transpose(f(:,:,1)),transpose(f(:,:,2)),1)
% plot(x_axis,sol,'r -','LineWidth',2)
% axis([x_a x_b y_a y_b])
% print('SlopeFieldSec1pt2Prob1b','-depsc',figure(1))
% stop

%

Nx=30; Ny=30;
x_a=0; x_b=2;
y_a=4; y_b=6;

dx=(x_b-x_a)/Nx; 
dy=(y_b-y_a)/Ny; 

f=zeros(Nx+1,Ny+1,2);
x_axis=zeros(Nx+1,1);
y_axis=zeros(Ny+1,1);
for iy=1:Ny+1
    y=y_a+dy*(iy-1);
    y_axis(iy,1)=y;
    for ix=1:Nx+1
        x=x_a+dx*(ix-1);
        x_axis(ix,1)=x;
        f(ix,iy,1) = 1;
        f(ix,iy,2) = 10-2*y;
    end
end

y_0=6;

sol=zeros(Nx+1,1);
for ix=1:Nx+1
    sol(ix,1)=5+(y_0-5)*exp(-2*x_axis(ix,1));
end

hold on
%clf
figure(1)
hold on
quiver(x_axis,y_axis,transpose(f(:,:,1)),transpose(f(:,:,2)),1)
plot(x_axis,sol,'r -','LineWidth',2)
axis([x_a x_b y_a y_b])
print('SlopeFieldSec1pt2Prob1c','-depsc',figure(1))
stop

