% Métodos Numéricos - Engs. Civil e Electrotécnica 
% exercico 2 da ficha 9
% Carlos Balsa - 2009/2010

f=@(x,y) 2*x/y-y*x;
x0=0;
xn=1;
y0=1;
h=0.2;
n=(xn-x0)/h;

% alinea a)
[x,ye]=ode_euler(f,[x0 xn],y0,n);

% alinea b)
[x,yem]=ode_meuler(f,[x0 xn],y0,n);

% alinea c)
x=[x0:h:xn];
[x,yrk]=ode45(f,x,y0);

%alínea d)
yex=sqrt(2-exp(-x.^2));


% alinea e)
clf
plot(x,ye,'-*r'); hold on
plot(x,yem,'-+g'); hold on
plot(x,yrk,'-xb'); hold on
plot(x,yex,'-ok'); hold on
grid on
legend('Euler','Euler Mod.','RK4','Exacta')