%*****************************************************************
%    Example for using the numerical integration and 
%    DE packages. You need to download the functions 
%    along with this file 
%    AUTHOR: Balu Santhanam
%    DATE  : 03/18/2001
%*****************************************************************
%    Numerical Integration
%
%    (a)  Symbolic Solution: 
     syms x
     area_sym = int(exp(-x)*sin(2*x),0,pi); 
     area_num = quad8('ft1',0,pi);
      
%    (b)  Sybolic solution 
     syms x 
     area_sym = int(cos(2*x),0,2*pi);
     area_num = quad8('ft2',0,2*pi);
%************************************************************************
%  Numerical Solutions to Differential Equations
                                
%  (a) Symbolic Solution: 
    y_act = dsolve('D3y = -D2y -Dy -y','y(0) = 1, Dy(0) = -1, D2y(0) = 2');
    t = [0:0.1:5]; TSPAN = [0 5]; init = [2 -1 1]; 
%   Numeric solution:
%   %   Assumed tolerance of e-4 
    [T,F] = ode23('de1',TSPAN,init)
    y_num = F(:,3); 
    y_act = -1/2*cos(T)+1/2*sin(T)+3/2*exp(-T);
    plot(T,y_num,'rx--',T,y_act,'m*--')
    set(gca,'FontName','Helvetica','FontSize',15)
    xlabel('Time instants for solution computation')
    ylabel('Solution to  DE 1')
    title('Numerical Solutions to DE via ODE solver')
    legend(gca,'Numerical','Symbolic')
    orient tall 
    print -deps de1.eps
    
%  (b) Symbolic Solution:  
    y_act = dsolve('D1y = 6 - 3*y','y(0) = 1');
    t = [0:0.1:5]; TSPAN = [0 5]; init = 1; 
%   Numeric Solution: 
%   Assumed tolerance of e-4
    [T,y_num] = ode23('de2',TSPAN,init)
    y_act = 2 - exp(-3*T);
    plot(T,y_num,'rx--',T,y_act,'m*--')
    set(gca,'FontName','Helvetica','FontSize',15)
    xlabel('Time instants for solution computation')
    ylabel('Solution to  DE 2')
    title('Numerical Solutions to DE via ODE solver')
    legend(gca,'Numerical','Symbolic')
    orient tall 
    print -deps de2.eps
%*********************************************************************

     
 
      
