%% HOW DO I DO THAT IN MATLAB SERIES?
% In this series, I am answering questions that students have asked
% me about MATLAB.  Most of the questions relate to a mathematical 
% procedure.

%% TOPIC
% How do I solve an ordinary differential equation
%% SUMMARY
% Language : Matlab 2010a; 
% Authors : Autar Kaw and Sri Harsha Garapati; 
% Mfile available at
% http://numericalmethods.eng.usf.edu/blog/calc_operations_ode_blog.m
% Last Revised : January 23, 2012; 
% Abstract: This program shows you how to solve an ordinary differential
% equation in MATLAB
clc
clear all
%% INTRODUCTION

disp('ABSTRACT')
disp('   This program shows you how to solve an ordinary differential equation')

disp(' ')
disp('AUTHOR')
disp('   Autar Kaw and Sri Harsha Garapati of http://autarkaw.wordpress.com')
disp(' ')
disp('MFILE SOURCE')
disp('   http://numericalmethods.eng.usf.edu/blog/calc_operations_ode_blog.m')
disp(' ')
disp('LAST REVISED')
disp('   January 23, 2012')
disp(' ')

%% INPUTS
  
% enter differential equation as string
eqn3='3*Dy+6*y=exp(-x)';  
% initial condition
inco='y(0)=6';            

%% DISPLAYING INPUTS
disp('  ')
disp('INPUTS')
% printing the the input ordinary differential equation with initial
% condition
fprintf('  equation to solve: %s\n  with: %s\n\n',eqn3,inco)

%% THE CODE

% "dsolve" is the command to solve the ordinary differential equation
% enter all as strings!!!
soln =dsolve(eqn3,inco,'x');
% convert the solution to a string to print in the outputs section
solnd=char(vpa(soln,4));
%% DISPLAYING OUTPUTS AND PLOTS
disp('  ')
disp('OUTPUTS')
% printing the outputs
fprintf('  The solution is: y=%s\n\n',solnd)

