H = hyCPN1()
H =
hyCPN1 with properties:
F: [1×1 struct]
phi: [1×1 struct]
H.F.state = [0 0 1 0 0 0 0 0 0 1 0 0 0;...
0 1 0 0 0 1 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 1 0 0];
H.F.stateDerivative = [1 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 1 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 1 1];
H.F.algebraic = [0 0 0 0 0 0 1 0 0 0 0 0 0;...
0 0 0 0 0 0 0 1 0 0 0 0 0];
H.F.boolean = [0 0 0 0 1 0 0 0 2 2 0 0 0];
H.F.input = [0 1 0 0 0 0 0 0 0 0 0 0 0;...
0 0 1 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 1 0 0 0 0];
H.phi.equality = [1 -0.13 0.13 0 0 0 0 0 0 0 0 0 0;...
0 0 0 1 0 0 0 0 0 0 -1 0 0;...
0 0 0 0 -1/1 1/1 0 0 0 0 15 0.5 0.5;...
0 -1 0 0 0 0 1 0 0 0 0 0 0;...
0 -1 0 0 0 0 1 0 0 0 0 0 0;...
0 0 -1 0 0 0 0 1 0 0 0 0 0];
H.phi.inequality = [0 0 0 0 0 0 0 0 -1 1 0 0 0;...
0 0 -1 0 0 0 0 1 0 0 0 0 0];
sys = dmss(H, 0);
At least one inequality is equal to an equation! The inequality has been reduced.
Reduced by 1 column(s) and 2 equation(s) with trivial Reduction due to duplications.
symEq = sys.symbolicEquations();
u = [1.2, 0.5, 0.8] .* ones(size(ut))';
u(50:100,3) = u(50:100,3) + 0.4 * (1:length(u(50:100,3)))'/length(u(50:100,3));
u(101:end,3) = u(101:end,3) + 0.4;
opt = odeset('RelTol', 10.0^(-3),'AbsTol',10.0^(-3), 'MaxStep', 1, 'MaxOrder',1);
sim = dmsim(sys, x0, ut, u, opt);
Seperation in 3 subset(s) with 6 subproblem(s), from which 6 are explicit solvable.
plot(sim.tsim, [sim.x, sim.y])
legend(["x1", "x2", "x3", "y1", "y2", "z1"])
plot3(sim.x(:,1), sim.x(:,2), sim.x(:,3))
% xp = [-2*10^-5; 0.3334; 0.3334];
% x = [0.8; 0.3332; 0.3332];
xp = sym('xp',[sys.n,1]);
J = sys.jacobian(xp, x, u, y, z);
disp([J.equality.stateDerivative, J.equality.state, J.equality.algebraic, J.equality.input, J.equality.boolean])
disp([J.inequality.stateDerivative, J.inequality.state, J.inequality.algebraic, J.inequality.input, J.inequality.boolean])
%disp(double(subs([J.equality.derivative, J.equality.float, J.equality.input, J.equality.boolean], 'f1', 1)))
%disp(double(subs([J.inequality.derivative, J.inequality.float, J.inequality.input, J.inequality.boolean], 'f1',1)))
symsys = sym2dmss(symEq, 0);
Reduced by 3 column(s) and 0 equation(s) with trivial Reduction due to duplications.
symSymEq = symsys.symbolicEquations();
J = symsys.jacobian(xp, x, u, y, z);
disp([J.equality.stateDerivative, J.equality.state, J.equality.algebraic, J.equality.input, J.equality.boolean])
disp([J.inequality.stateDerivative, J.inequality.state, J.inequality.algebraic, J.inequality.input, J.inequality.boolean])
u = [1.2, 0.5, 0.8] .* ones(size(ut))';
u(ut>50,3) = u(ut>50,3) + 0.4;
simD = dmsim(sysD, x0, ut, u);
plot(simD.tsim, [simD.x, simD.y, simD.z])
plot3(simD.x(:,1), simD.x(:,2), simD.x(:,3))
categories = categorical({'continuous', 'discrete'});
categories = reordercats(categories,{'continuous', 'discrete'});
text(1:length(times),times,num2str(times'),'vert','bottom','horiz','center');
ylabel('simulation time [sec]')
sysC = sysD.d2c();
System reduced algebraicly by 3 algebraic variable(s) and 3 equation(s).
sysCEq = sysC.symbolicEquations();
u = [1.2, 0.5, 0.8] .* ones(size(ut))';
u(ut>50,3) = u(ut>50,3) + 0.4;
simC = dmsim(sysC, x0, ut, u);
Seperation in 3 subset(s) with 6 subproblem(s), from which 6 are explicit solvable.
sysD2 = sysD.d2d(ts2);
System reduced algebraicly by 3 algebraic variable(s) and 3 equation(s).
sysD2Eq = sysD2.symbolicEquations();
u = [1.2, 0.5, 0.8] .* ones(size(ut))';
u(ut>50,3) = u(ut>50,3) + 0.4;
simD2 = dmsim(sysD2, x0, ut, u);
H.F.stateDerivative = [];
H.F.algebraic = ["true" "0" ""];
H.F.input = ["" "true" "";...
H.phi.equality = ["true" -1 2];
boolEq = boolSys.symbolicEquations();
J = boolSys.jacobian(xp, x, u, y, z);
disp([J.equality.stateDerivative, J.equality.state, J.equality.algebraic, J.equality.input, J.equality.boolean])
plantEq = ["xp1 - 0.13*u1*u2 + 0.13*x1*u3 = 0";...
controllerEq = ["xp1 - x2 = 0";...
"xp2 + x1 + 15*x2 - z1 = 0";...
"(u1 - u2) * (2*z1 - 1) <= 0"];
plantSys = sym2dmss(plantEq, 0);
Reduced by 2 column(s) and 0 equation(s) with trivial Reduction due to duplications.
plantSys.stateName = "fluidlevel";
plantSys.inputName = ["available flow rate", "entry valve position", "exit valve position"];
plantSys.algebraicName = ["entry flow rate", "exit flow rate"];
plantSys.outputIndex.state = 1;
plantSys.outputIndex.algebraic = [1, 2];
plantSys.symbolicEquations
ans =

controllerSys = sym2dmss(controllerEq, 0);
Reduced by 1 column(s) and 0 equation(s) with trivial Reduction due to duplications.
controllerSys.stateName = ["entry valve position", "filter signal"];
controllerSys.inputName = ["fluidlevel", "desired level"];
controllerSys.booleanName = "logic signal";
controllerSys.outputIndex.boolean = 1;
controllerSys.symbolicEquations
ans =

closedLoopSys = appendedSys.connect();
% closedLoopSys.symbolicEquations
u = [1.2, 0.5, 0.8] .* ones(size(ut))';
u(50:end,3) = u(50:end,3) + 0.4;
closedLoopSim = dmsim(closedLoopSys, x0, ut, u, opt);
Seperation in 3 subset(s) with 6 subproblem(s), from which 6 are explicit solvable.
plot(closedLoopSim.tsim, [closedLoopSim.x, closedLoopSim.y])
clear closedLoopSys closedLoopSim
closedLoopSys = connect(plantSys, controllerSys);
% closedLoopSys.symbolicEquations
closedLoopSim = dmsim(closedLoopSys, x0, ut, u, opt);
Seperation in 3 subset(s) with 6 subproblem(s), from which 6 are explicit solvable.
plot(closedLoopSim.tsim, [closedLoopSim.x, closedLoopSim.y])
clear closedLoopSys closedLoopSim appendedSys plantSys controllerSys
plantSys = sym2dmss(plantEq, 0);
Reduced by 2 column(s) and 0 equation(s) with trivial Reduction due to duplications.
controllerSys = sym2dmss(controllerEq, 0);
Reduced by 1 column(s) and 0 equation(s) with trivial Reduction due to duplications.
appendedSys = append(plantSys, controllerSys);
stateConnections = [2, 2; 4, 1] ;
algebraicConnections = [];
closedLoopSys = appendedSys.connect(stateConnections, algebraicConnections, booleanConnections, similarInputs);
% closedLoopSys.symbolicEquations
closedLoopSim = dmsim(closedLoopSys, x0, ut, u, opt);
Seperation in 3 subset(s) with 6 subproblem(s), from which 6 are explicit solvable.
plot(closedLoopSim.tsim, [closedLoopSim.x, closedLoopSim.y])
closedLoopSysD = closedLoopSys.c2d(0.1);
System reduced algebraicly by 3 algebraic variable(s) and 3 equation(s).
stateCurrentRange = [0 1.5; 0 1; -0.2 0.2];
stateTargetRange = [-1 1; -1 1; -1 1];
algebraicCurrentRange = [0 1; 0 1];
algebraicTargetRange = [-1 1; -1 1];
[closedLoopSysNorm, xOffset, xSlope, ~,~, yOffset, ySlope ]= closedLoopSysD.normalize(stateCurrentRange, stateTargetRange, [], [], algebraicCurrentRange, algebraicTargetRange);
%opt = odeset('RelTol',1e-6,'AbsTol', 1e-9, 'MaxStep', 1); %, 'MaxStep', 3600/2); %('RelTol',1e-5,'AbsTol', 1e-6);
ut = 0:closedLoopSysNorm.ts:150;
u = [1.2, 0.5, 0.8] .* ones(size(ut))';
u(ut>50,3) = u(ut>50,3) + 0.4;
x0n = (x0 - xOffset')./xSlope';
normSim = dmsim(closedLoopSysNorm, x0n, ut, u);%, opt, method);
toc()
Elapsed time is 0.367981 seconds.
xSim = normSim.x .* xSlope + xOffset;
ySim = normSim.y .* ySlope + yOffset;
plot(normSim.zt, normSim.z)