%% Time and Frequency Response of Sparse Second-Order Model
% For this example, consider tuningForkData.mat that contains the sparse second-order model of a tuning fork being struck gently but quickly on one of its tines. The system has one input, the pressure applied on one of its tines, which results in two outputs - the displacements at the tip and base of the tuning fork.
% Load the sparse matrices from tuningForkData.mat into the workspace and create the mechss model object.

load('tuningForkData.mat','M','K','B','F');
sys = mechss(M,[],K,B,F,'InputName','pressure','Outputname',{'y tip','x base'})

% Next, set solver options for the model by setting the UseParallel parameter to true and the DAESolver to use trbdf3. Use spy to inspect the model structure. Enabling parallel computing requires a Parallel Computing Toolbox™ license.

sys.SolverOptions.UseParallel = true;
sys.SolverOptions.DAESolver = 'trbdf3';
spy(sys)

% You can also use showStateInfo to examine the components.

showStateInfo(sys)

% Use step to obtain the step response plot of the system. You need to provide the time vector or final time for sparse models.

t = linspace(0,0.5,1000);
step(sys,t)

% Next, obtain the Bode plot to examine the frequency response. You need to provide the frequency vector for sparse models.

w = logspace(1,5,1000);
bode(sys,w), grid

% Copyright 2020 The MathWorks, Inc.