Contents

Aaron Klapheck

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

disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%                                                                %')
disp('%                         Test 3.                                %')
disp('%                    Programer: Aaron Klapheck                   %')
disp('%                                                                %')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')

fprintf('\n')


% Solve: y'' + y = F/m*sin(t); y(0) = 0, y'(0) = 0, F = m = 1
% Solution: y(t) = 1/2*sin(t) - 1/2*t*cos(t)
%
% Analytic solution:
% t = [0:.1:30];
% y = 1/2.*sin(t) - 1/2.*t.*cos(t);
%
%
%
%
% got solution from: http://www.ibiblio.org/links/devmodules/forcedsm/
%
% Their problem: y'' + w^2*y = F/m*sin(wt), y(0) = x_0, y'(0) = v_0.
%   where w, F, and m are constants.
%
% Their solution: y(t) = A*cos(wt) + B*sin(wt) - (F/m)/(2w)*t*cos(wt).
%   where A = x_0, and B = v_0/w + (F/m)/(2w^2).
%
The date and time: 16-Apr-2008 10:43:52 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                %
%                         Test 3.                                %
%                    Programer: Aaron Klapheck                   %
%                                                                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Number 1.

disp('%%%% Number 1. %%%%%')

% Solve Using MATLAB's ODE45 solver.




Tspan = [0 30];
initc = [0, 0];
p = [1, 1];

[T, Y] = ode45(@SolveODE2nd, Tspan, initc, [], p);



% Anilytical function.

t = [0:.1:30];
y = 1/2.*sin(t) - 1/2.*t.*cos(t);


% Plot both

figure(1)
plot(T, Y(:,1),t, y), ...
    legend('Numerical MATLAB', 'Exact')
%%%% Number 1. %%%%%

Number 2.

disp('%%%% Number 2. %%%%%')

% Solve Using Simulink's Embedded function block.





fprintf('\nDirrectory is: \n')
dir

load SecondOrderEmbed.mat

fprintf('\nDisplay all variables: \n')
whos



% Anilytical function.

t = [0:.1:30];
y = 1/2.*sin(t) - 1/2.*t.*cos(t);


% Plot both

figure(2)
plot(SecondTransferEmbed(1,:), SecondTransferEmbed(2,:),t, y), ...
    legend('Numerical Simulink Embedded Function', 'Exact')
%%%% Number 2. %%%%%

Dirrectory is: 

.                                  SimSolveDE2ndEmbed_sfun.dll        
..                                 SimSolveDE2ndTransfer.mdl          
PracticeTest3_Driver.asv           SimSolveDE2ndTransferScopeOut.mdl  
PracticeTest3_Driver.m             SolveODE1st.m                      
SecondOrder.mat                    SolveODE2nd.m                      
SecondOrderEmbed.mat               Transfer_Functions.asv             
SecondOrderTransfer.mat            Transfer_Functions.m               
SimSolveDE1st.mdl                  firstOrder.mat                     
SimSolveDE2nd.mdl                  html                               
SimSolveDE2ndEmbed.mdl             


Display all variables: 
  Name                      Size                    Bytes  Class

  ScopeData                52x2                       832  double array
  SecondTransferEmbed       2x53                      848  double array
  SecondTransfered          2x52                      832  double array
  T                       157x1                      1256  double array
  Tspan                     1x2                        16  double array
  Y                       157x2                      2512  double array
  initc                     1x2                        16  double array
  p                         1x2                        16  double array
  t                         1x301                    2408  double array
  tout                     52x1                       416  double array
  y                         1x301                    2408  double array

Grand total is 1445 elements using 11560 bytes

Simulink Model:

Number 3.

disp('%%%% Number 3. %%%%%')

% Solve Using Simulink's Transfer function block.






fprintf('\nDirrectory is: \n')
dir

load SecondOrderTransfer.mat

fprintf('\nDisplay all variables: \n')
whos



% Anilytical function.

t = [0:.1:30];
y = 1/2.*sin(t) - 1/2.*t.*cos(t);


% Plot both

figure(3)
plot(SecondTransfered(1,:), SecondTransfered(2,:),t, y), ...
    legend('Numerical Simulink Transfer Function', 'Exact')
%%%% Number 3. %%%%%

Dirrectory is: 

.                                  SimSolveDE2ndEmbed_sfun.dll        
..                                 SimSolveDE2ndTransfer.mdl          
PracticeTest3_Driver.asv           SimSolveDE2ndTransferScopeOut.mdl  
PracticeTest3_Driver.m             SolveODE1st.m                      
SecondOrder.mat                    SolveODE2nd.m                      
SecondOrderEmbed.mat               Transfer_Functions.asv             
SecondOrderTransfer.mat            Transfer_Functions.m               
SimSolveDE1st.mdl                  firstOrder.mat                     
SimSolveDE2nd.mdl                  html                               
SimSolveDE2ndEmbed.mdl             


Display all variables: 
  Name                      Size                    Bytes  Class

  ScopeData                52x2                       832  double array
  SecondTransferEmbed       2x53                      848  double array
  SecondTransfered          2x52                      832  double array
  T                       157x1                      1256  double array
  Tspan                     1x2                        16  double array
  Y                       157x2                      2512  double array
  initc                     1x2                        16  double array
  p                         1x2                        16  double array
  t                         1x301                    2408  double array
  tout                     52x1                       416  double array
  y                         1x301                    2408  double array

Grand total is 1445 elements using 11560 bytes

Simulink Model:

Number 4.

disp('%%%% Number 4. %%%%%')

% Solve Using Simulink's Transfer function block. Alter the scope so that
% it will output the variables. Remember to run the Simulink model first!



fprintf('\nDisplay all variables: \n')
whos


% Anilytical function.

t = [0:.1:30];
y = 1/2.*sin(t) - 1/2.*t.*cos(t);


% Plot both

figure(4)
plot(ScopeData(:, 1), ScopeData(:, 2),t, y), ...
    legend('Numerical Simulink Transfer Function', 'Exact')
%%%% Number 4. %%%%%

Display all variables: 
  Name                      Size                    Bytes  Class

  ScopeData                52x2                       832  double array
  SecondTransferEmbed       2x53                      848  double array
  SecondTransfered          2x52                      832  double array
  T                       157x1                      1256  double array
  Tspan                     1x2                        16  double array
  Y                       157x2                      2512  double array
  initc                     1x2                        16  double array
  p                         1x2                        16  double array
  t                         1x301                    2408  double array
  tout                     52x1                       416  double array
  y                         1x301                    2408  double array

Grand total is 1445 elements using 11560 bytes

Simulink Model: