%% Script sim_nonlinear_model_demo
%  
%  File:   sim_nonlinear_model_demo.m
%  Author: Peter Polcz <ppolcz@gmail.com> 
%  
%  Created on 2017. November 02.
%
%%
try c = evalin('caller','persist'); catch; c = []; end
persist = pcz_persist(mfilename('fullpath'), c); clear c; 
persist.backup();
%clear persist

global PUBLISH
PUBLISH = 1;

%% Generate snapshots
open_system 'sim_nonlinear_model'
print -dpng '-ssim_nonlinear_model' fig/sim_nonlinear_model.png
print -dpng '-ssim_nonlinear_model/Nonlinear Crane Model' fig/sim_nonlinear_model_2.png
print -dpng '-ssim_nonlinear_model/Nonlinear Crane Model/Linear and nonlinear system model' ...
    fig/sim_nonlinear_model_3.png

%% Simulink simulation
% <sim_nonlinear_model.slx Simulink>
% 
% Simulink model: <br>
% <fig/sim_nonlinear_model.png img> <br>
% Nonlinear crane model: <br>
% <fig/sim_nonlinear_model_2.png img> <br>
% Linear and nonlinear system model: <br>
% <fig/sim_nonlinear_model_3.png img> <br>
% 
% Simulation without any control. However, the length of the crane $l(t)$
% is controlled, otherwise it tends to $-\infty$.

simout = sim('sim_nonlinear_model');
simulate_crane