% HW2_Bank_script.m -->  with HW2_Bank.mdl
%
% script for Simulink tutorial for bank balance example from HW2
% For EGR 326 class example,  
% 
% Author: J Cardell
% Date: Feb 2017

% DEFINE CONSTANTS, INITIAL CONDITIONS and SYSTEM MATRICES
% You must open the associated block in your Simulink model and enter the
% variable name, such as 'k', 'm', 'x1_0' etc. These variables then obtain
% their assigned values in the Matlab script.

% Constants / Parameters
d = 10;     % monthly deposit
i = 0.01;   % Interest

% Initial conditions
bal0 = 0;

% SIMULATE THE DYNAMIC SYSTEM
% run the simulink model, mass_spring.mdl, defining the start and stop
% times for the simulation
sim('HW1_Bank');
set_param('HW1_Bank','StartTime','0','StopTime','25')

% PLOT SYSTEM BEHAVIOR
figure
hold on
% Define vectors to be used for output plot
% NOTE that to obtain the 'time' vector you must select the "structure with
% time" option from the appropriate "To Workspace" block in your model
t = simout.time;
y = simout.signals.values;

% Create and label plot of system behavior
plot(t, y, 'LineWidth', 2)    
title('Bank Balance')
xlabel('t (sec)')
ylabel('Balance ($)')
grid
hold off



