Contents

Aaron Klapheck

% Lab #7 20-Mar-08
% continued in next lab.
clear, clc, home
fprintf('The date and time: %s \n', datestr(now))
The date and time: 08-Apr-2008 14:02:12 

Notes

% Ordinary Differential Equations (ODE's)
%   see pages 729 in text book
%
%   Have Driver:
%   Call a user-defined function that stores a FODE for 1st order
%   Call a user-defined function that stores a FODE for 3rd order
%   Call a user-defined function that stores a FODE for nth order
%       Use the internet to research site.
%       Put link in Header Line 1.
%

Solve 12.12 a

clear, clc, home
fprintf('The date and time: %s \n \n', datestr(now))

disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%                                               %')
disp('%         Purpose: Solve 12.12 (a)              %')
disp('%                                               %')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')


% Solve: dy/dt = t^2/z - y; y(0) = 1

Tspan = [0 30];
initc = 0;
a = 1;

[T, Y] = ode45(@SolveODE1stA,Tspan,initc,[],a);



% Anilytical function.

t = [0:.1:30];


y = 1/a.*(t.^2 - 2.*t + 2 + (a - 2).*exp(-t));


figure(2)
plot(T, Y, t, y), legend('MATLAB Numeric Solution', 'Exact Solution')
The date and time: 08-Apr-2008 14:02:13 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                               %
%         Purpose: Solve 12.12 (a)              %
%                                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Solve 12.12 c

clear, clc, home
fprintf('The date and time: %s \n \n', datestr(now))

disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%                                               %')
disp('%         Purpose: Solve 12.12 (c)              %')
disp('%                                               %')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')


% Solve: dy/dt = at + bty; y(0) = 1

Tspan = [0 30];
initc = 0;
a = 1;
b = 1;

[T, Y] = ode45(@SolveODE1st,Tspan,initc,[],a,b);




% Anilytical function.

t = [0:.1:30];


y = -1/b.*(a - (a + b).*exp((b.*t.^2)./2));


figure(2)
plot(T,log(Y),t, log(y)), legend('MATLAB Numeric Solution', 'Exact Solution')
The date and time: 08-Apr-2008 14:02:15 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                               %
%         Purpose: Solve 12.12 (c)              %
%                                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Warning: Log of zero.