%Math 316 - Spring 2017
%Written by M. Motamed @ UNM 
%==========================================================
%EXAMPLE 6 of Chapter 2. 
%IVP: 3 x y^2 y'= - y^3 -x & y(1)=1
%==========================================================

[x,y]=meshgrid((-5:.02:5),(-5:.02:5));
psi=@(x,y) x.*y.^3+x.^2/2;

%(a) the 3-dimensional illustration of the function psi of two variables
figure(1)
surf(x,y,psi(x,y)); 
shading interp
xlabel('x')
ylabel('y')
zlabel('\Psi')
set(gca,'fontsize', 12);

%(b) the countour level illustration of the function psi of two variables
figure(2)
[C,h]=contour(x,y,psi(x,y),[0 1 2 5 10],'Linewidth',1.5); 
clabel(C,h)
xlabel('x')
ylabel('y')
set(gca,'fontsize', 12);

%(c) plotting the solution using its implicit form 
x0=1; y0=1;
figure(3)
contour(x,y,psi(x,y),[1.5 1.5],'b','Linewidth',1.5)
hold on
plot(x0,y0,'*r','Linewidth',3)
xlabel('x')
ylabel('y')
grid on
set(gca,'fontsize', 12);

%(d) Plotting the soluting using its explicit form for 1<=x<=5
x=linspace(1,5,10000);
y=(abs(3./(2*x)-x/2)).^(1/3);
y(x>sqrt(3))=-y(x>sqrt(3));
figure(4)
plot(x,y,'Linewidth',1.5)
xlabel('x')
ylabel('y')
grid on
set(gca,'fontsize', 12);
