% System Dynamics ---------------------------------------------------------
u(1)+0.1+k2*(4-x(6))-k*sqrt(2*g)*sqrt(x(1)); % tank 1
k*sqrt(2*g)*(sqrt(x(1))-sqrt(x(2))); % tank 2
k*sqrt(2*g)*(sqrt(x(2))-sqrt(x(3))); % tank 3
k*sqrt(2*g)*(sqrt(x(3))-sqrt(x(4))); % tank 4
k*sqrt(2*g)*(sqrt(x(4))-sqrt(x(5))); % tank 5
k*sqrt(2*g)*(sqrt(x(5))-sqrt(x(6))); % tank 6
tank = nonlinearSys('tank',f);
% Parameters --------------------------------------------------------------
params.R0 = zonotope([[2; 4; 4; 2; 10; 4],0.2*eye(6)]);
params.U = zonotope([0,0.005]);
% Reachability Settings ---------------------------------------------------
options.zonotopeOrder = 50;
options.lagrangeRem.simplify = 'simplify';
% Reachability Analysis ---------------------------------------------------
R = reach(tank, params, options);
% Simulation --------------------------------------------------------------
simRes = simulateRandom(tank, params, simOpt);
% Visualization -----------------------------------------------------------
dims = {[1 2],[3 4],[5 6]};
subplot(1,3,k); hold on; box on;
useCORAcolors("CORA:contDynamics")
plot(R,projDim,'DisplayName','Reachable set');
plot(R(1).R0,projDim, 'DisplayName','Initial set');
% plot simulation results
plot(simRes,projDim,'DisplayName','Simulations');
xlabel(['x_{',num2str(projDim(1)),'}']);
ylabel(['x_{',num2str(projDim(2)),'}']);