├── @conMatZonotope ├── conMatZonotope.m ├── conZonotope.m ├── matZonotope.m ├── mtimes.m └── plus.m ├── @intervalMatrix ├── abs.m ├── center.m ├── dependentTerms.m ├── display.m ├── dominantVertices.m ├── exactSquare.m ├── expm.m ├── expmAbsoluteBound.m ├── expmDifferentAlgorithms.m ├── expmInd.m ├── expmIndMixed.m ├── expmMixed.m ├── expmNormInf.m ├── expmTaylorHornerScaling.m ├── expmVertex.m ├── exponentialRemainder.m ├── interval.m ├── intervalMatrix.m ├── logRemainder.m ├── matPolytope.m ├── matZonotope.m ├── mpower.m ├── mtimes.m ├── norm.m ├── plot.m ├── plus.m ├── powers.m ├── private │ ├── hornerTaylorSeries.m │ ├── intervalMatrixRemainder.m │ ├── scalingSquaringHornerTaylorSeries.m │ └── taylorSeries.m ├── rad.m ├── randomIntervalMatrix.m ├── randomSampling.m ├── subsref.m ├── vertices.m └── volume.m ├── @matZonotope ├── center.m ├── concatenate.m ├── dependentTerms.m ├── display.m ├── dominantVertices.m ├── expm.m ├── expmInd.m ├── expmIndMixed.m ├── expmMixed.m ├── expmOneParam.m ├── expmVertex.m ├── intervalMatrix.m ├── matPolytope.m ├── matZonotope.m ├── mpower.m ├── mtimes.m ├── norm.m ├── plot.m ├── plus.m ├── powers.m ├── randomSampling.m ├── reduce.m ├── subsref.m ├── vertices.m ├── volume.m └── zonotope.m ├── @nonlinearDT ├── checkOptionsReach.m ├── linError_mixed_noInt_DT.m ├── linReach_DT.m ├── linearize_DT.m ├── nonlinearDT.m └── reach_DT.m ├── Figures └── idea3.png ├── README.md ├── examples-basic ├── a_linearDT.m ├── a_nonlinearDT.m └── a_polyDT.m ├── examples-cmz ├── b_linearDT_measnoise.m ├── b_linearDT_sideInfo.m └── b_polyDT_sideInfo.m ├── plotting ├── p_plot_linearDT_measnoise.m ├── p_plot_linearDT_sideInfo.m └── p_plot_polyDT_sideInfo.m ├── utilities ├── compLipConst.m ├── minBeta.m └── polyFun.m └── workspace └── paper ├── run_3appIn10S2_0_005w_0_002v_red390.mat ├── run_poly.mat ├── run_poly2.mat ├── run_poly3.mat └── run_side001In10S3_0_005w_red200.mat /@conMatZonotope/conMatZonotope.m: -------------------------------------------------------------------------------- 1 | classdef conMatZonotope < matZonotope 2 | % conZonotope - object constructor for constrained matrix zonotopes [1] 3 | % 4 | % Syntax: 5 | % C = [0 0; 0 0]; 6 | % G{1} = [1 3; -1 2]; 7 | % G{2} = [2 0; 1 -1]; 8 | % A{1} = [1 1; 0 1]; 9 | % A{2} = [0.3 0.2;-0.2 0.1]; 10 | % B = [0.5 0.4; 0.3 0.2]; 11 | % 12 | % cmz = conMatZonotope(C,G,A,B); 13 | % 14 | % Outputs: 15 | % cmz - Generated Object 16 | % 17 | % Example: 18 | % 19 | % References: 20 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer,Karl Henrik Johansson 21 | % "Data-Driven Reachability Analysis from Noisy Data" 22 | % 23 | % Other m-files required: none 24 | % Subfunctions: none 25 | % MAT-files required: none 26 | % 27 | % See also: 28 | % 29 | % Author: Amr Alanwar 30 | % Written: 03-December-2020 31 | % Last update: --- 32 | % Last revision: 33 | 34 | %------------- BEGIN CODE -------------- 35 | 36 | properties (SetAccess = private, GetAccess = public) 37 | A = []; 38 | B = []; 39 | end 40 | 41 | methods 42 | 43 | % class constructor 44 | function obj = conMatZonotope(varargin) 45 | 46 | if nargin==3 47 | if isa(varargin{1},'conZonotope') 48 | CZ = varargin{1}; 49 | numofcolc = varargin{2}; 50 | numofcolA = varargin{3}; 51 | %extract center 52 | matrixCenter=CZ.Z(:,1); 53 | %extract generator matrix 54 | oldgenerator=CZ.Z(:,2:end); 55 | %obtain matrix center 56 | center = vec2mat(matrixCenter,numofcolc); 57 | %obtain matrix generators 58 | if ~isempty(oldgenerator) 59 | for i=1:length(oldgenerator(1,:)) 60 | generator{i}=vec2mat(oldgenerator(:,i),numofcolc); 61 | end 62 | else 63 | generator{1} = zeros(size(matrixCenter)); 64 | end 65 | 66 | 67 | if ~isempty(CZ.A) 68 | for i=1:length(CZ.A(1,:)) 69 | A{i}=vec2mat(CZ.A(:,i),numofcolA); 70 | end 71 | else 72 | A{1} = zeros(size(matrixCenter)); 73 | end 74 | B = vec2mat(CZ.b,numofcolA); 75 | end 76 | elseif nargin == 4 77 | center = varargin{1}; 78 | generator = varargin{2}; 79 | A = varargin{3}; 80 | B = varargin{4}; 81 | else 82 | error('This class takes 4 inputs.') 83 | end 84 | 85 | % create a zonotope 86 | obj@matZonotope(center,generator); 87 | 88 | 89 | obj.A = A; 90 | obj.B = B; 91 | end 92 | 93 | 94 | % methods in seperate files 95 | cZ = plus(summand1,summand2); 96 | cZ = mtimes(factor1,factor2); 97 | res = reduce(obj,method,orderG,varargin); 98 | res = conZonotope(obj,varargin); 99 | % res = and(obj,S); 100 | % cZ = cartProd(cZ1,cZ2); 101 | % res = center(obj); 102 | % cZ = convHull(cZ1,varargin); 103 | % d = dim(obj); 104 | % display(obj); 105 | % cZ = enclose(varargin); 106 | % res = in(obj1,obj2,varargin); 107 | % res = interval(obj); 108 | % res = intervalMultiplication(obj,I); 109 | % res = isempty(obj); 110 | % res = isFullDim(obj); 111 | % res = isIntersecting(obj1,obj2,varargin); 112 | % res = mptPolytope(obj); 113 | 114 | % cZ = or(cZ1, varargin); 115 | % handle = plot(obj,varargin); 116 | % handle = plotZono(obj,varargin); 117 | % pZ = polyZonotope(obj); 118 | % obj = project(obj,dims); 119 | % cZquad = quadMap(varargin); 120 | 121 | % res = rescale(obj,varargin); 122 | % cZsplit = split(obj,varargin); 123 | % [val,x,ksi] = supportFunc(obj,dir,varargin); 124 | % V = vertices(obj); 125 | % res = zonoBundle(obj); 126 | 127 | 128 | end 129 | 130 | 131 | end 132 | 133 | %------------- END OF CODE ------- -------------------------------------------------------------------------------- /@conMatZonotope/conZonotope.m: -------------------------------------------------------------------------------- 1 | function Z = conZonotope(CmatZ) 2 | % zonotope - Converts a constrained matrix zonotope into a constranied zonotope 3 | % 4 | % Syntax: 5 | % Z = zonotope(matZ) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % 10 | % Outputs: 11 | % Z - zonotope 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: plus 20 | 21 | % Author: Amr Alanwar 22 | % Written: 18-December-2020 23 | % Last update: --- 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %concert center 29 | center=mat2vec(CmatZ.center); 30 | 31 | %convert generators 32 | for i=1:CmatZ.gens 33 | generatorMatrix(:,i) = mat2vec(CmatZ.generator{i}); 34 | end 35 | 36 | for i=1:length(CmatZ.A) 37 | AMatrix(:,i) = mat2vec(CmatZ.A{i}); %TODO remove the {1} 38 | end 39 | Bvec= mat2vec(CmatZ.B); 40 | %instantiate constrained zonotope 41 | Z=conZonotope([center,generatorMatrix],AMatrix,Bvec); 42 | 43 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@conMatZonotope/matZonotope.m: -------------------------------------------------------------------------------- 1 | function res = matZonotope(obj,varargin) 2 | % zonotope - over-approximates a constrained matrix zonotope with a matrix zonotope 3 | % 4 | % Syntax: 5 | % res = matZonotope(obj) 6 | % res = matZonotope(obj,alg) 7 | % 8 | % Inputs: 9 | % obj - conZonotope object 10 | % alg - algorithm used to compute enclosure ('nullSpace' or 'reduce') 11 | % 12 | % Outputs: 13 | % res - zonotope object 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: interval 22 | 23 | % Author: 24 | % Written: 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | if nargin >= 2 31 | alg = varargin{1}; 32 | else 33 | alg = 'nullSpace'; 34 | end 35 | 36 | if(strcmp(alg,'liftup')) 37 | % Z_up = zonotope([X_data_cmz{i+1,1}.Z; -X_data_cmz{i+1,1}.b, X_data_cmz{i+1,1}.A]); 38 | 39 | newcen = [obj.center;-obj.B{1}]; 40 | for i=1:length(obj.generator) 41 | newgen{i} = [obj.generator{i};obj.A{1}{i} ] ; 42 | end 43 | res = matZonotope(newcen,newgen); 44 | else 45 | numOfColc = size(obj.center,2); 46 | CZ=conZonotope(obj); 47 | alg = 'nullSpace'; 48 | if nargin >= 3 49 | alg = varargin{2}; 50 | end 51 | %convert to zonotope 52 | CZred = zonotope(CZ, alg); 53 | 54 | %convert back to matrix zonotope 55 | res = matZonotopeConv(CZred,numOfColc); 56 | end 57 | % parse input arguments 58 | end 59 | 60 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@conMatZonotope/mtimes.m: -------------------------------------------------------------------------------- 1 | function cMZ = mtimes(factor1,factor2) 2 | % mtimes - Overloaded '.*' operator for the multiplication of a matrix or an 3 | % interval matrix with a constrained matrix zonotope 4 | % 5 | % Syntax: 6 | % cZ = times(cmz,cZ) 7 | % 8 | % Inputs: 9 | % cmz - constrained matrix zonotope 10 | % cz - conZonotope or zonotope object 11 | % 12 | % Outputs: 13 | % cZ - constrained zonotpe after multiplication 14 | % 15 | % Example: 16 | % 17 | % G = [0 1 0 1;0 1 2 -1]; 18 | % A = [-2 1 -1]; 19 | % b = 2; 20 | % cz = conZonotope(Z,A,b); 21 | % cMul = [3 1;2 4] * cz; 22 | % 23 | % hold on 24 | % plot(cZono,[1,2],'r'); 25 | % plot(cMul,[1,2],'b'); 26 | % 27 | % Other m-files required: none 28 | % Subfunctions: none 29 | % MAT-files required: none 30 | % 31 | % See also: plus 32 | 33 | % Author: Amr Alanwar 34 | % Written: 35 | % Last update: --- 36 | % Last revision:--- 37 | 38 | %------------- BEGIN CODE -------------- 39 | 40 | if isa(factor2,'conZonotope') 41 | if isempty(factor2.A) 42 | % The multiplication consists of three terms as shown in [1] 43 | matrixczono = factor1; 44 | czono = factor2; 45 | % Znew has the center which is (cmz.center*cz.center) 46 | % add to Znew the cmz.center * cz.generator 47 | Znew=matrixczono.center*czono.Z; 48 | for i=1:matrixczono.gens 49 | % add to Znew the cmz.generator * cz.center 50 | Zadd=matrixczono.generator{i}*czono.Z(:,1); 51 | Znew(:,(end+1):(end+length(czono.Z(1,1))))=Zadd; 52 | end 53 | %find constrain from cmz 54 | Amat =[]; 55 | for j=1:length(factor1.A) 56 | Amat(:,j) = mat2vec(factor1.A{j}) ; 57 | end 58 | bmat = mat2vec(factor1.B); 59 | %noOfGen = matrixczono.gens + size(czono.Z(:,2:end),2) +matrixczono.gens * size(czono.Z(:,2:end),2); 60 | %adding constraint in the following way 61 | % 0(for cz.A) cmz.A 0(remaining) 62 | sizLeftZeros = size(czono.Z(:,2:end),2); 63 | sizeRightZeros = matrixczono.gens * size(czono.Z(:,2:end),2); 64 | Anew= [ zeros(size(Amat,1),sizLeftZeros),Amat,... 65 | zeros(size(Amat,1),sizeRightZeros)]; 66 | %% 67 | Beta_matzono=minBeta(conZonotope(ones(2,size(Amat,2)+1),Amat,bmat)); 68 | % find max beta 69 | index=1; 70 | for i =1:size(Amat,2) 71 | for j=1:size(czono.Z(:,2:end),2) 72 | Beta_t(index) = Beta_matzono(i)*interval(-1,1);%noneed for multiplication 73 | temp = Beta_t(index); 74 | maxfac(index) = max(abs(temp.inf),abs(temp.sup)); 75 | index = index+1; 76 | end 77 | end 78 | %multiply betas and find the factor f 79 | index=1; 80 | for i=1:matrixczono.gens 81 | %generators * generators 82 | for j=1:size(czono.Z(:,2:end),2) 83 | Zadd=matrixczono.generator{i}*czono.Z(:,j+1)*maxfac(index); 84 | Znew(:,end+1)=Zadd; 85 | index = index+1; 86 | end 87 | end 88 | 89 | cMZ = conZonotope( Znew,... 90 | Anew,bmat); 91 | else 92 | matrixczono = factor1; 93 | czono = factor2; 94 | % The multiplication consists of three terms as shown in [1] 95 | % Znew has the center which is (cmz.center*cz.center) 96 | % add to Znew the cmz.center * cz.generator 97 | Znew=matrixczono.center*czono.Z; 98 | for i=1:matrixczono.gens 99 | % add to Znew the cmz.generator * cz.center 100 | Zadd=matrixczono.generator{i}*czono.Z(:,1); 101 | Znew(:,(end+1):(end+length(czono.Z(1,1))))=Zadd; 102 | end 103 | 104 | %Total number of generators = #of cmz.generators + #of cz.generator 105 | %+ #of cmz.generators * #of cz.generator 106 | noOfGen = matrixczono.gens + length(czono.Z(:,2:end)) +matrixczono.gens * length(czono.Z(:,2:end)); 107 | % concatinate zeros to cz.A to have the same number of generator 108 | diffczA = noOfGen - size(czono.A,2); 109 | %the constraints from the cz 110 | Anew =[ czono.A, zeros(size(czono.A,1),diffczA)]; 111 | Bnew =[ czono.b]; 112 | %% 113 | %add the constraints from cmz 114 | Amat =[]; 115 | for i=1:matrixczono.gens 116 | Amat(:,i) = mat2vec(matrixczono.A{i}); 117 | end 118 | Bmat = mat2vec(matrixczono.B); 119 | Bnew = [ Bnew;Bmat]; 120 | 121 | %adding constraint in the following way 122 | % 0(for cz.A) cmz.A 0(remaining) 123 | numOfRemainZeors = noOfGen - size(Amat,2)-size(czono.A,2); 124 | Anew =[Anew; zeros(size(Amat,1),size(czono.A,2)),Amat,... 125 | zeros(size(Amat,1),numOfRemainZeors)]; 126 | %% 127 | % find beta for cz 128 | Beta_czono=minBeta(czono); 129 | % find beta for cmz 130 | Beta_matzono=minBeta(conZonotope(ones(2,size(Amat,2)+1),Amat,Bmat)); 131 | 132 | %multiply betas and find the factor f 133 | index=1; 134 | for i =1:size(Amat,2) 135 | for j=1:size(czono.A,2) 136 | Beta_t(index) = Beta_matzono(i)*Beta_czono(j); 137 | temp = Beta_t(index); 138 | maxfac(index) = max(abs(temp.inf),abs(temp.sup)); 139 | index = index+1; 140 | end 141 | end 142 | %add the remaining generators multiplied by a factor 143 | index=1; 144 | for i=1:matrixczono.gens 145 | %generators * generators 146 | for j=1:size(czono.A,2) 147 | Zadd=matrixczono.generator{i}*czono.Z(:,j+1)*maxfac(index); 148 | Znew(:,end+1)=Zadd; 149 | index = index+1; 150 | end 151 | end 152 | 153 | cMZ = conZonotope( Znew,... 154 | Anew,Bnew); 155 | end 156 | elseif isa(factor2,'zonotope') 157 | %same code as constrained zonotope with empty A 158 | matrixczono = factor1; 159 | czono = factor2; 160 | Znew=matrixczono.center*czono.Z; 161 | 162 | for i=1:matrixczono.gens 163 | %mat generators * center 164 | Zadd=matrixczono.generator{i}*czono.Z(:,1); 165 | Znew(:,(end+1):(end+length(czono.Z(1,1))))=Zadd; 166 | end 167 | Amat =[]; 168 | for j=1:length(factor1.A) 169 | Amat(:,j) = mat2vec(factor1.A{j}) ; 170 | end 171 | bmat = mat2vec(factor1.B); %*factor2.Z(:,1)]; 172 | %noOfGen = matrixczono.gens + size(czono.Z(:,2:end),2) +matrixczono.gens * size(czono.Z(:,2:end),2); 173 | sizLeftZeros = size(czono.Z(:,2:end),2); 174 | sizeRightZeros = matrixczono.gens * size(czono.Z(:,2:end),2); 175 | Anew= [ zeros(size(Amat,1),sizLeftZeros),Amat,... 176 | zeros(size(Amat,1),sizeRightZeros)]; 177 | %% 178 | Beta_matzono=minBeta(conZonotope(ones(2,size(Amat,2)+1),Amat,bmat)); 179 | 180 | index=1; 181 | for i =1:size(Amat,2) 182 | for j=1:size(czono.Z(:,2:end),2) 183 | Beta_t(index) = Beta_matzono(i)*interval(-1,1);%noneed for multiplication 184 | temp = Beta_t(index); 185 | maxfac(index) = max(abs(temp.inf),abs(temp.sup)); 186 | index = index+1; 187 | end 188 | end 189 | index=1; 190 | for i=1:matrixczono.gens 191 | %generators * generators 192 | for j=1:size(czono.Z(:,2:end),2) 193 | Zadd=matrixczono.generator{i}*czono.Z(:,j+1)*maxfac(index); 194 | Znew(:,end+1)=Zadd; 195 | index = index+1; 196 | end 197 | end 198 | 199 | cMZ = conZonotope( Znew,... 200 | Anew,bmat); 201 | elseif isnumeric(factor2) 202 | cMZCenGen = mtimes@matZonotope(factor1,factor2); 203 | cMZ = conMatZonotope(cMZCenGen.center,cMZCenGen.generator,factor1.A,factor1.B); 204 | else 205 | cMZ = mtimes@matZonotope(factor1,factor2); 206 | end 207 | 208 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@conMatZonotope/plus.m: -------------------------------------------------------------------------------- 1 | function R = plus(summand1,summand2) 2 | % plus - Overloaded '+' operator for the Minkowski addition of a 3 | % constrained matrix zonotope with other set representations 4 | % 5 | % Syntax: 6 | % cZ = plus(summand1,summand2) 7 | % 8 | % Inputs: 9 | % summand1 - conMatZonotope object or numerical vector 10 | % summand2 - conMatZonotope object or numerical vector 11 | % 12 | % Outputs: 13 | % R - constrained matrix Zonotope after Minkowski addition 14 | % 15 | % References: 16 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer,Karl Henrik Johansson 17 | % "Data-Driven Reachability Analysis from Noisy Data" 18 | % 19 | % 20 | % Other m-files required: none 21 | % Subfunctions: none 22 | % MAT-files required: none 23 | % 24 | % See also: mtimes 25 | % 26 | % References: 27 | % 28 | % Author: Amr Alanwar 29 | % Written: 12-December 2020 30 | % Last update: 9-May 2021 31 | % 32 | % Last revision:--- 33 | 34 | %------------- BEGIN CODE -------------- 35 | 36 | % find a conMatZonotope object 37 | if isa(summand1, 'conMatZonotope') 38 | matCZ=summand1; 39 | summand=summand2; 40 | elseif isa(summand2, 'conMatZonotope') 41 | matCZ=summand2; 42 | summand=summand1; 43 | end 44 | 45 | % handle different classes of the second summand 46 | if isa(summand, 'conMatZonotope') 47 | 48 | %Calculate minkowski sum 49 | %Add the centers 50 | newcenter = matCZ.center + summand.center; 51 | 52 | if isempty(matCZ.generator) 53 | newgenerator = summand.generator; 54 | newA = summand.A; 55 | newB = summand.B; 56 | elseif isempty(summand.generator) 57 | newgenerator = matCZ.generator; 58 | newA = matCZ.A; 59 | newB = matCZ.B; 60 | else 61 | %concatenate matrix generators 62 | newgenerator = matCZ.generator; 63 | newgenerator((end+1):(end+summand.gens)) = summand.generator; 64 | for i=1:length(matCZ.A) 65 | newA{i} =blkdiag(matCZ.A{i},zeros(size(summand.A{1}))); 66 | end 67 | index=1; 68 | for i=length(matCZ.A)+1:length(matCZ.A)+length(summand.A) 69 | newA{i} =blkdiag(zeros(size(matCZ.A{1})),summand.A{index}); 70 | index = index +1; 71 | end 72 | newB =blkdiag(matCZ.B,summand.B); 73 | end 74 | 75 | 76 | R= conMatZonotope(newcenter,newgenerator,newA,newB); 77 | 78 | elseif isa(summand, 'matZonotope') 79 | newcenter = matCZ.center + summand.center; 80 | 81 | if isempty(matCZ.generator) 82 | newgenerator = summand.generator; 83 | R= conMatZonotope(newcenter,newgenerator,matCZ.A,matCZ.B); 84 | elseif isempty(summand.generator) 85 | newgenerator = matCZ.generator; 86 | R= conMatZonotope(newcenter,newgenerator,matCZ.A,matCZ.B); 87 | else 88 | %concatenate matrix generators 89 | newgenerator = matCZ.generator; 90 | newA = matCZ.A; 91 | newgenerator((end+1):(end+summand.gens)) = summand.generator; 92 | 93 | %add zeros to A to have the same number of matrices 94 | numOldA = length(matCZ.A); 95 | for i=1:summand.gens 96 | newA{numOldA+i} = zeros(size(summand.generator{1})); 97 | end 98 | 99 | 100 | R= conMatZonotope(newcenter,newgenerator,newA,matCZ.B); 101 | end 102 | 103 | 104 | elseif isnumeric(summand) 105 | R= conMatZonotope(matCZ.center+summand,matCZ.generator,matCZ.A,matCZ.B); 106 | end 107 | 108 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/abs.m: -------------------------------------------------------------------------------- 1 | function M = abs(intMat) 2 | % abs - returns the absolute value bound of an interval matrix 3 | % 4 | % Syntax: 5 | % M = abs(intMat) 6 | % 7 | % Inputs: 8 | % intMat - interval matrix 9 | % 10 | % Outputs: 11 | % M - absolute value bound 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: 20 | 21 | % Author: Matthias Althoff 22 | % Written: 21-July-2010 23 | % Last update: 26-August-2011 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | Minf=infimum(intMat.int); 29 | Msup=supremum(intMat.int); 30 | 31 | M=max(abs(Minf), abs(Msup)); 32 | 33 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/center.m: -------------------------------------------------------------------------------- 1 | function c = center(obj) 2 | % center - Returns the center of an intervalMatrix 3 | % 4 | % Syntax: 5 | % c = center(obj) 6 | % 7 | % Inputs: 8 | % obj - intervalMatrix object 9 | % 10 | % Outputs: 11 | % c - center of the intervalMatrix obj 12 | % 13 | % Example: 14 | % M = intervalMatrix(eye(2),2*eye(2)); 15 | % c = center(M) 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: none 22 | 23 | % Author: Victor Gassmann 24 | % Written: 23-July-2020 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | c = 1/2*(obj.Inf + obj.Sup); 31 | 32 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/dependentTerms.m: -------------------------------------------------------------------------------- 1 | function [intSq,intH] = dependentTerms(obj,r) 2 | % dependentTerms - computes exact Taylor terms of an interval matrix square 3 | % and an interval matrix exponential 4 | % 5 | % These different tasks are computed in one m-file to save computation 6 | % time: the for loop has to be executed only once and help functions do not 7 | % have to be called so often 8 | % 9 | % Syntax: 10 | % [intSq,intH] = dependentTerms(obj,r) 11 | % 12 | % Inputs: 13 | % obj - linear interval system (linIntSys) object 14 | % r - time step increment 15 | % 16 | % Outputs: 17 | % intSq - exact square matrix 18 | % intH - exact Taylor terms up to second order 19 | % 20 | % Example: 21 | % 22 | % Other m-files required: none 23 | % Subfunctions: none 24 | % MAT-files required: none 25 | % 26 | % See also: 27 | 28 | % Author: Matthias Althoff 29 | % Written: 20-February-2007 30 | % Last update: 30-April-2007 31 | % 23-September-2010 32 | % Last revision:--- 33 | 34 | %------------- BEGIN CODE -------------- 35 | 36 | %load data from object structure 37 | A=obj.int; 38 | dim=obj.dim; 39 | 40 | %initialize the square of A (sq), the first term of the interval 41 | %exponential (H) 42 | sq=0*A; 43 | H=0*A; 44 | I=eye(dim); %identity matrix 45 | 46 | %get diagonal elements of A (diagA) 47 | diagA=interval(zeros(dim),zeros(dim)); %initialize 48 | for i=1:dim 49 | diagA(i,i)=A(i,i); 50 | end 51 | 52 | %compute elements of sq and H 53 | for i=1:dim 54 | %i neq j 55 | %auxiliary value s 56 | s=sum(A,i); 57 | %auxiliary value b 58 | b=A(i,:); b(i)=0; 59 | %auxiliary matrix C 60 | C=I*A(i,i)+diagA; 61 | %compute non-diagonal elements of sq 62 | sq(i,:)=b*C+s; 63 | %compute non-diagonal elements of H 64 | H(i,:)=b*(I*r+0.5*C*r^2)+0.5*r^2*s; 65 | 66 | %i=j 67 | %compute diagonal elements of sq 68 | sq(i,i)=sq(i,i)+A(i,i)^2; 69 | %auxiliary values for H, Hu 70 | a_inf=infimum(A(i,i)); 71 | a_sup=supremum(A(i,i)); 72 | %compute diagonal elements for H 73 | kappa=max(a_inf*r+0.5*a_inf^2*r^2, a_sup*r+0.5*a_sup^2*r^2); 74 | H(i,i)=H(i,i)+interval(g(A(i,i),r),kappa); 75 | %-------------------------------------------------------------- 76 | end 77 | 78 | %write as interval matrices 79 | intSq=intervalMatrix(r^2*center(sq),r^2*rad(sq)); 80 | intH=intervalMatrix(center(H)+I,rad(H)); 81 | 82 | end 83 | 84 | 85 | % AUXILIARY FUNCTIONS 86 | 87 | function [res]=g(a,r) 88 | if isIntersecting(interval(-1/r,-1/r),a) 89 | res=-0.5; 90 | else 91 | a_inf=infimum(a); 92 | a_sup=supremum(a); 93 | res=min(a_inf*r+0.5*a_inf^2*r^2, a_sup*r+0.5*a_sup^2*r^2); 94 | end 95 | end 96 | 97 | 98 | function [res]=gu(a,r) 99 | if in(interval(-3/(2*r)),a) 100 | res=-9/24*r; 101 | else 102 | a_inf=infimum(a); 103 | a_sup=supremum(a); 104 | res=min(0.5*a_inf*r^2+1/6*a_inf^2*r^3,... 105 | 0.5*a_sup*r^2+1/6*a_sup^2*r^3); 106 | end 107 | end 108 | 109 | 110 | function s=sum(A,i) 111 | %sum function: 112 | %s=0.5 \sum_{k:k\neq i,k\neq j} a_{ik}a_{kj}t^2 113 | n=length(A); 114 | k=0:n; 115 | ind=k*n+1:n+1:n^2; 116 | A(ind)=zeros(n,1); 117 | 118 | s=A(i,:)*A; 119 | end 120 | 121 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/display.m: -------------------------------------------------------------------------------- 1 | function display(intMat) 2 | % display - Displays the interval matrix 3 | % 4 | % Syntax: 5 | % display(intMat) 6 | % 7 | % Inputs: 8 | % intMat - interval matrix 9 | % 10 | % Outputs: 11 | % --- 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: none 20 | 21 | % Author: Matthias Althoff 22 | % Written: 18-June-2010 23 | % Last update: --- 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %display dimension, generators 29 | disp('dimension: '); 30 | disp(intMat.dim); 31 | %display left and right limits 32 | disp('left limit: '); 33 | disp(infimum(intMat.int)); 34 | disp('right limit: '); 35 | disp(supremum(intMat.int)); 36 | 37 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/dominantVertices.m: -------------------------------------------------------------------------------- 1 | function matV = dominantVertices(matI, maxNumber) 2 | % dominantVertices - computes the dominant vertices of an interval matrix 3 | % 4 | % Syntax: 5 | % matV = dominantVertices(matI, maxNumber) 6 | % 7 | % Inputs: 8 | % matI - interval matrix 9 | % maxNumber - maximum number of dominant vertices 10 | % 11 | % Outputs: 12 | % matV - cell array of matrix vertices 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 02-July-2010 24 | % Last update: 19-July-2010 25 | % 25-July-2016 (intervalhull replaced by interval) 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %conversion to an interval 31 | IH = interval(matI); 32 | 33 | %get edge lengths 34 | edgeLen = 2*rad(IH); 35 | 36 | %sort edge lengths 37 | [edgeLenSorted, ind] = sort(edgeLen,'descend'); 38 | 39 | %set default value 40 | if maxNumber==inf 41 | unlimited=1; 42 | nrOfParameters = length(find(edgeLen>0)); 43 | maxNumber = 2^nrOfParameters; 44 | else 45 | unlimited=0; 46 | end 47 | 48 | %start at center 49 | V = center(IH); 50 | 51 | %add new vertices 52 | counter = 1; 53 | nrOfVertices=1; 54 | while ((nrOfVertices*2)<(maxNumber+2)) && (counter<=length(edgeLen)) 55 | %current index 56 | currInd = ind(counter); 57 | %obtain Vleft vertices 58 | Vleft = V; 59 | Vleft(currInd,:) = V(currInd,:) - 0.5*edgeLenSorted(counter); 60 | %obtain Vright vertices 61 | Vright = V; 62 | Vright(currInd,:) = V(currInd,:) + 0.5*edgeLenSorted(counter); 63 | %combine vertices 64 | V = [Vleft,Vright]; 65 | %update counter, nrOfVertices 66 | counter = counter+1; 67 | nrOfVertices = nrOfVertices*2; 68 | end 69 | 70 | %convert vertices to matrix vertices 71 | if unlimited 72 | matV=cell(length(V(1,:)),1); 73 | else 74 | matV=cell(length(V(1,:))+2,1); 75 | end 76 | for i=1:length(V(1,:)) 77 | matV{i}=vec2mat(V(:,i)); 78 | end 79 | 80 | %sup and inf matrices are also dominant! 81 | if ~unlimited 82 | matV{i+1} = infimum(matI.int); 83 | matV{i+2} = supremum(matI.int); 84 | end 85 | 86 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/exactSquare.m: -------------------------------------------------------------------------------- 1 | function Asq = exactSquare(Aint) 2 | % exactSquare - computes the exact square of an interval matrix 3 | % 4 | % The computation is according to [1]. 5 | % 6 | % A more easily understandable implementation can be found in the unit 7 | % test 'test_intervalMatrix_exactSquare'. 8 | % 9 | % Syntax: 10 | % Asq = exactSquare(Aint) 11 | % 12 | % Inputs: 13 | % A - interval matrix 14 | % 15 | % Outputs: 16 | % Asq - resulting interval matrix 17 | % 18 | % Example: 19 | % - 20 | % 21 | % References: 22 | % [1] Kosheleva, O.; Kreinovich, V.; Mayer, G. & Nguyen, H. T. Computing the 23 | % cube of an interval matrix is NP-Hard Proc. of the ACM symposium on 24 | % Applied computing, 2005, 1449-1453 25 | % 26 | % Other m-files required: none 27 | % Subfunctions: none 28 | % MAT-files required: none 29 | % 30 | % See also: 31 | % 32 | % Author: Matthias Althoff 33 | % Written: 04-January-2009 34 | % Last update: 02-November-2017 35 | % Last revision:--- 36 | 37 | %------------- BEGIN CODE -------------- 38 | 39 | %extract intervals 40 | A = Aint.int; 41 | 42 | %obtain dimension 43 | dim=length(A); 44 | 45 | %initialize 46 | sq=0*A; 47 | E=eye(dim); %identity matrix 48 | 49 | %compute result for diagonal and non-diagonal elements 50 | %compute elements of H, Hu and sq 51 | for i=1:dim 52 | %i neq j 53 | %auxiliary value s 54 | s=sum(A,i); 55 | %auxiliary value b 56 | b=A(i,:); b(i)=0; 57 | %auxiliary matrix C 58 | C=E*A(i,i)+diag(diag(A)); 59 | %compute non-diagonal elements of sq 60 | sq(i,:)=b*C+s; 61 | 62 | %i=j 63 | %compute diagonal elements of sq 64 | sq(i,i)=sq(i,i)+A(i,i)^2; 65 | end 66 | 67 | % include result in intervalMatrix object 68 | Asq = intervalMatrix([]); 69 | Asq.int = sq; 70 | 71 | %sum function: 72 | %s=\sum_{k:k\neq i,k\neq j} a_{ik}a_{kj} 73 | function s=sum(A,i) 74 | 75 | % for k=1:length(A) 76 | % A(k,k)=0; 77 | % end 78 | 79 | %get indices that should be 0 80 | n=length(A); 81 | k=0:n; 82 | ind=k*n+1:n+1:n^2; 83 | A(ind)=zeros(n,1); 84 | 85 | s=A(i,:)*A; 86 | 87 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expm.m: -------------------------------------------------------------------------------- 1 | function [eI, iPow, E] = expm(varargin) 2 | % expm - operator for the exponential matrix of an 3 | % interval matrix, evaluated dependently 4 | % 5 | % Syntax: 6 | % eI = expm(intMat) 7 | % eI = expm(intMat,maxOrder) 8 | % [eI, iPow, E] = expm(intMat,r,maxOrder) 9 | % 10 | % Inputs: 11 | % intMat - interval matrix 12 | % maxOrder - maximum Taylor series order until remainder is computed 13 | % r - time step size 14 | % 15 | % Outputs: 16 | % eI - interval matrix exponential 17 | % iPow - cell array storing the powers of the matrix: 18 | % A,A^2,...,A^(intermediateOrder) 19 | % E - interval matrix for the remainder 20 | % 21 | % Example: 22 | % C = [0 1;0 -2.5]; 23 | % D = [0 0;0 0.5]; 24 | % intMat = intervalMatrix(C,D); 25 | % 26 | % eI = expm(intMat) 27 | % 28 | % Other m-files required: none 29 | % Subfunctions: none 30 | % MAT-files required: none 31 | % 32 | % See also: plus 33 | 34 | % Author: Matthias Althoff 35 | % Written: 18-June-2010 36 | % Last update: 06-July-2010 37 | % 05-August-2010 38 | % Last revision:--- 39 | 40 | %------------- BEGIN CODE -------------- 41 | 42 | if nargin == 1 43 | 44 | intMat = varargin{1}; 45 | maxOrder = 10; 46 | 47 | %compute exact terms 48 | [sq,H] = dependentTerms(intMat,1); 49 | 50 | initialOrder = 2; 51 | initialPower = sq; 52 | 53 | %init eI 54 | eI = H; 55 | 56 | elseif nargin == 2 57 | 58 | intMat = varargin{1}; 59 | maxOrder = varargin{2}; 60 | 61 | %compute exact terms 62 | [sq,H] = dependentTerms(intMat,1); 63 | 64 | initialOrder = 2; 65 | initialPower = sq; 66 | 67 | %init eI 68 | eI = H; 69 | 70 | 71 | elseif nargin==3 72 | intMat = varargin{1}; 73 | r = varargin{2}; 74 | maxOrder = varargin{3}; 75 | 76 | %compute exact terms 77 | [sq,H] = dependentTerms(intMat*(1/r),r); 78 | 79 | initialOrder = 2; 80 | initialPower = sq; 81 | 82 | %init eI 83 | eI = H; 84 | 85 | elseif nargin==5 86 | intMat = varargin{1}; 87 | r = varargin{2}; 88 | maxOrder = varargin{3}; 89 | initialOrder = varargin{4}; 90 | initialPower = varargin{5}; 91 | 92 | %init eI 93 | eI=initialPower*(1/factorial(initialOrder)); 94 | end 95 | 96 | %compute powers 97 | iPow=powers(intMat,maxOrder,initialOrder,initialPower); 98 | 99 | %compute Taylor series 100 | for i=(initialOrder+1):maxOrder 101 | eI = eI + iPow{i}*(1/factorial(i)); 102 | end 103 | 104 | %compute exponential remainder 105 | E = exponentialRemainder(intMat,maxOrder); 106 | 107 | %final result 108 | eI = eI+E; 109 | 110 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmAbsoluteBound.m: -------------------------------------------------------------------------------- 1 | function absBound = expmAbsoluteBound(intMat,t) 2 | % expmAbsoluteBound - returns the over-approximation of the absolute bound 3 | % of the symmetric solution of the computation of the mapping mimicing the 4 | % exponential 5 | % 6 | % Syntax: 7 | % absBound = expmAbsoluteBound(intMat,t) 8 | % 9 | % Inputs: 10 | % intMat - interval matrix 11 | % t - time 12 | % 13 | % Outputs: 14 | % absBound - matrix specifying the absolute bound 15 | % 16 | % Example: 17 | % 18 | % Other m-files required: none 19 | % Subfunctions: none 20 | % MAT-files required: none 21 | % 22 | % See also: plus 23 | 24 | % Author: Matthias Althoff 25 | % Written: 02-July-2010 26 | % Last update: --- 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | %extract nominal matrix and symmetric interval matrix 32 | infA = infimum(intMat.int); 33 | supA = supremum(intMat.int); 34 | A = 0.5*(supA+infA); 35 | S = 0.5*(supA-infA); 36 | 37 | %set starting order 38 | j=2; 39 | 40 | %derive norm values 41 | absA = abs(A); 42 | 43 | %generate identity and zero matrices 44 | dim = intMat.dim; 45 | I = eye(dim); 46 | O = zeros(dim); 47 | 48 | %build G matrix 49 | G = [absA*t/j O O;... 50 | S*t/j (absA+S)*t/j O;... 51 | O I I]; 52 | 53 | %compute approximated Ginf 54 | %Ginf_test = G^100; 55 | 56 | %compute via left and right eigenvectors 57 | %right eigenvector 58 | [Y,eigvalY] = eig(G); 59 | %left eigenvector 60 | [Q,eigvalQ] = eig(G.'); 61 | Q = conj(Q); 62 | 63 | %select eigenvectors with eigenvalue one 64 | ind_y = find(diag(eigvalY)==1); 65 | ind_q = find(diag(eigvalQ)==1); 66 | 67 | %check correct ordering of eigenvectors 68 | %Q.'*Y 69 | 70 | %compute Ginf 71 | Ginf = zeros(3*dim); 72 | for i=1:dim 73 | %get y and q^T 74 | y = Y(:,ind_y(i)); 75 | qt = Q(:,ind_q(i)).'; 76 | Ginf = Ginf + y*qt/(qt*y); 77 | end 78 | 79 | %set initial right hand side 80 | auxMat = [absA*t; S*t; O]; 81 | 82 | %multiply right hand side with Ginf 83 | auxMat = Ginf*auxMat; 84 | 85 | %get absolue bound 86 | absBound = auxMat((2*dim+1):(3*dim),:); 87 | 88 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmDifferentAlgorithms.m: -------------------------------------------------------------------------------- 1 | function result = expmDifferentAlgorithms(intMat,maxOrder,styleOfCalculation,varargin) 2 | % returns the approximation of e^intMat using different algorithms 3 | % with maxOrder iterations. It is used as a fassade to access the 4 | % algorithms in the private directory 5 | % 6 | % Syntax: 7 | % result = expmDifferentAlgorithms(intMat,maxOrder,styleOfCalculation,varargin); 8 | % 9 | % Inputs: 10 | % intMat - intervalMatrix (nxn) 11 | % maxOrder - maximum order of the TaylorSeries, has to be > abs(intMat) +2 12 | % styleOfCalculation - a number used to indicate the algorithm which 13 | % should be used for the caluclation of the approximation 14 | % varargin - is a list which contains optional parameter for other 15 | % calculations with extra knowledge needed. 16 | % e.g. the potential for the scaling and squaring process 17 | % 18 | % Outputs: 19 | % result - the exponentiation with the chosen algorithm 20 | % 21 | % Example: 22 | % 23 | % Other m-files required: hornerTaylorSeries.m, taylorSeries.m, 24 | % intervalMatrixRemainder.m, scalingSquaringHornerTaylorSeries 25 | % Subfunctions: none 26 | % MAT-files required: none 27 | % 28 | % See also: 29 | 30 | % Author: Ivan Brkan 31 | % Written: 23-April-2019 32 | % Last update: 29-April-2019 33 | % Last revision:--- 34 | 35 | %------------- BEGIN CODE -------------- 36 | 37 | try 38 | 39 | switch styleOfCalculation 40 | 41 | case 0 42 | % case of truncated Taylor series 43 | result = taylorSeries(intMat,maxOrder); 44 | case 1 45 | % case of truncated Taylor series using horner scheme 46 | result = hornerTaylorSeries(intMat,maxOrder); 47 | case 2 48 | % case of truncated Taylor series using horner scheme and the 49 | switch length(varargin) 50 | case 0 51 | % no potential was given as attribute, 52 | % so 1 is used as the default value 53 | result = scalingSquaringHornerTaylorSeries(intMat,maxOrder,1); 54 | case 1 55 | tmp = cell2mat(varargin); 56 | result = scalingSquaringHornerTaylorSeries(intMat,maxOrder,tmp(1)); 57 | otherwise 58 | result = []; 59 | end 60 | 61 | case 4 62 | r = 1; 63 | result = expm(intMat,r,maxOrder); 64 | 65 | otherwise 66 | result = []; 67 | end 68 | 69 | catch 70 | result = []; 71 | end 72 | 73 | end 74 | 75 | -------------------------------------------------------------------------------- /@intervalMatrix/expmInd.m: -------------------------------------------------------------------------------- 1 | function [eI, iPow, E] = expmInd(varargin) 2 | % expmInd - operator for the exponential matrix of an 3 | % interval matrix, evaluated independently 4 | % 5 | % Syntax: 6 | % eI = expmInd(intMat,maxOrder) 7 | % 8 | % Inputs: 9 | % intMat - interval matrix 10 | % maxOrder - maximum Taylor series order until remainder is computed 11 | % 12 | % Outputs: 13 | % eI - interval matrix exponential 14 | % iPow - cell array storing the powers of the matrix: 15 | % A,A^2,...,A^(intermediateOrder) 16 | % E - interval matrix for the remainder 17 | % 18 | % Example: 19 | % 20 | % Other m-files required: none 21 | % Subfunctions: none 22 | % MAT-files required: none 23 | % 24 | % See also: plus 25 | 26 | % Author: Matthias Althoff 27 | % Written: 18-June-2010 28 | % Last update: 06-July-2010 29 | % 05-August-2010 30 | % Last revision:--- 31 | 32 | %------------- BEGIN CODE -------------- 33 | maxOrder =2; 34 | initialOrder = 0; 35 | intMat = varargin{1}; 36 | initialPower = eye(6);%intMat^0; 37 | %compute powers 38 | iPow=powers(intMat,maxOrder); 39 | 40 | if nargin==2 41 | intMat = varargin{1}; 42 | maxOrder = varargin{2}; 43 | initialOrder = 0; 44 | initialPower = intMat^0; 45 | 46 | %compute powers 47 | iPow=powers(intMat,maxOrder); 48 | elseif nargin==4 49 | intMat = varargin{1}; 50 | maxOrder = varargin{2}; 51 | initialOrder = varargin{3}; 52 | initialPower = varargin{4}; 53 | 54 | %compute powers 55 | iPow=powers(intMat,maxOrder,initialOrder,initialPower); 56 | end 57 | 58 | %compute finite Taylor series 59 | %initialize matrix zonotope 60 | eI=initialPower*(1/factorial(initialOrder)); 61 | 62 | %compute Taylor series 63 | for i=(initialOrder+1):maxOrder 64 | eI = eI + iPow{i}*(1/factorial(i)); 65 | end 66 | 67 | %compute exponential remainder 68 | E = exponentialRemainder(intMat,maxOrder); 69 | 70 | %final result 71 | eI = eI+E; 72 | 73 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmIndMixed.m: -------------------------------------------------------------------------------- 1 | function [eI,eI2,iPow,iPow2,E] = expmIndMixed(matI,intermediateOrder,maxOrder) 2 | % expmIndMixed - dummy function for interval matrices. 3 | % 4 | % Syntax: 5 | % expmIndMixed(matI,intermediateOrder,maxOrder) 6 | % 7 | % Inputs: 8 | % matI - matrix interval 9 | % intermediate Order - Taylor series order until computation is 10 | % performed with matrix zonotopes 11 | % maxOrder - maximum Taylor series order until remainder is computed 12 | % 13 | % Outputs: 14 | % eZ - matrix zonotope exponential part 15 | % eI - interval matrix exponential part 16 | % iPow - cell array storing the powers of the matrix: 17 | % A,A^2,...,A^(intermediateOrder) 18 | % iPow2 - cell array storing the powers of the matrix: 19 | % A^(intermediateOrder+1),...,A^(maxOrder) 20 | % E - interval matrix for the remainder 21 | % 22 | % Example: 23 | % 24 | % Other m-files required: none 25 | % Subfunctions: none 26 | % MAT-files required: none 27 | % 28 | % See also: plus 29 | 30 | % Author: Matthias Althoff 31 | % Written: 13-September-2010 32 | % Last update: --- 33 | % Last revision:--- 34 | 35 | %------------- BEGIN CODE -------------- 36 | 37 | %compute powers 38 | iPow=powers(matI,intermediateOrder); 39 | 40 | %compute finite Taylor series 41 | %initialize matrix zonotope 42 | eI=matI^0; 43 | 44 | %compute finite Taylor sum 45 | for i=1:intermediateOrder 46 | eI = eI + iPow{i}*(1/factorial(i)); 47 | end 48 | 49 | %compute interval part 50 | [eI2,iPow2,E] = expmInd(matI, maxOrder, ... 51 | intermediateOrder+1, matI*iPow{intermediateOrder}); 52 | 53 | 54 | 55 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmMixed.m: -------------------------------------------------------------------------------- 1 | function [eI,eI2,iPow,iPow2,E] = expmMixed(matI,r,intermediateOrder,maxOrder) 2 | % expmIndMixed - dummy function for interval matrices. 3 | % 4 | % Syntax: 5 | % [eI,eI2,iPow,iPow2,E] = expmMixed(matI,r,intermediateOrder,maxOrder) 6 | % 7 | % Inputs: 8 | % matI - interval matrix object 9 | % r - time-step size 10 | % intermediateOrder - max taylor order for the first part of evaluation 11 | % maxOrder - max taylor order for the second part of evaluation 12 | % 13 | % Outputs: 14 | % eI - interval matrix for the first part of evaluation 15 | % eI2 - interval matrix for the second part of evaluation 16 | % iPow - cell array storing the powers of the matrix: 17 | % A,A^2,...,A^(intermediateOrder) 18 | % iPow2 - cell array storing the powers of the matrix: 19 | % A^(intermediateOrder+1),...,A^(maxOrder) 20 | % E - interval matrix for the remainder 21 | % 22 | % Example: 23 | % 24 | % Other m-files required: none 25 | % Subfunctions: none 26 | % MAT-files required: none 27 | % 28 | % See also: plus 29 | 30 | % Author: Matthias Althoff 31 | % Written: 13-September-2010 32 | % Last update: --- 33 | % Last revision:--- 34 | 35 | %------------- BEGIN CODE -------------- 36 | 37 | if (intermediateOrder>=2) 38 | 39 | %compute exact terms 40 | [sq,H] = dependentTerms(matI*(1/r),r); 41 | 42 | %init eI 43 | eI = H; 44 | 45 | %compute powers 46 | iPow=powers(matI,intermediateOrder,2,sq); 47 | 48 | %add first power for input computatins 49 | iPow{1}=matI; 50 | 51 | %compute finite Taylor sum 52 | for i=3:intermediateOrder 53 | eI = eI + iPow{i}*(1/factorial(i)); 54 | end 55 | 56 | %compute interval part 57 | [eI2,iPow2,E] = expm(matI, r, ... 58 | maxOrder, intermediateOrder+1, matI*iPow{intermediateOrder}); 59 | 60 | else 61 | disp('intermediate order too low'); 62 | end 63 | 64 | 65 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmNormInf.m: -------------------------------------------------------------------------------- 1 | function val = expmNormInf(intMat,t) 2 | % expmNormInf - returns the over-approximation of the inf-norm of the 3 | % symmetric solution of the computation of the mapping mimicing the 4 | % exponential 5 | % 6 | % Syntax: 7 | % val = expmNormInf(intMat,t) 8 | % 9 | % Inputs: 10 | % intMat - interval matrix 11 | % t - time 12 | % 13 | % Outputs: 14 | % val - value of the norm 15 | % 16 | % Example: 17 | % 18 | % Other m-files required: none 19 | % Subfunctions: none 20 | % MAT-files required: none 21 | % 22 | % See also: plus 23 | 24 | % Author: Matthias Althoff 25 | % Written: 25-June-2010 26 | % Last update: --- 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | %extract nominal matrix and symmetric interval matrix 32 | infA = infimum(intMat.int); 33 | supA = supremum(intMat.int); 34 | A = 0.5*(supA+infA); 35 | S = 0.5*(supA-infA); 36 | 37 | %set starting order 38 | j=2; 39 | 40 | %derive norm values 41 | nA = norm(A,inf); 42 | nS = norm(S,inf); 43 | nAS = norm(abs(A) + S,inf); 44 | 45 | %compute summand1 46 | summand1 = (nA*nS*t^2/j)/(nA*(nAS)*t^2/j^2 - (nA+nAS)*t/j + 1); 47 | summand2 = nS*t/(1 - nAS*t/j); 48 | 49 | %final result 50 | val = summand1 + summand2; 51 | 52 | % %Tests----------------------------------- 53 | % %build G matrix 54 | % G = [nA*t/j 0 0;... 55 | % nS*t/j nAS*t/j 0;... 56 | % 0 1 1]; 57 | % 58 | % %compute approximated Ginf 59 | % Ginf = G^100; 60 | % 61 | % %set initial vector 62 | % initVec = [nA*t; nS*t; 0]; 63 | % 64 | % %final result 65 | % val2 = [0 0 1]*Ginf*initVec; 66 | 67 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmTaylorHornerScaling.m: -------------------------------------------------------------------------------- 1 | function result = expmTaylorHornerScaling(intMat,maxOrder,styleOfCalculation,varargin) 2 | % returns the approximation of e^intMat using different algorithms 3 | % with maxOrder iterations. It is used as a fassade to access the 4 | % algorithms in the private directory 5 | % 6 | % Syntax: 7 | % val = expmTaylorHornerScaling(intMat,maxOrder,StyleOfCalculation); 8 | % 9 | % Inputs: 10 | % intMat - intervalMatrix (nxn) 11 | % maxOrder - maximum order of the TaylorSeries, has to be > abs(intMat) +2 12 | % styleOfCalculation - a number used to indicate the algorithm which 13 | % should be used for the caluclation of the approximation 14 | % varargin - is a list which contains optional parameter for other 15 | % calculations with extra knowledge needed. 16 | % e.g. the potential for the scaling and squaring process 17 | % 18 | % Outputs: 19 | % result - the exponentiation with the chosen algorithm 20 | % 21 | % Example: 22 | % 23 | % Other m-files required: hornerTaylorSeries.m, taylorSeries.m, 24 | % intervalMatrixRemainder.m, scalingSquaringHornerTaylorSeries 25 | % Subfunctions: none 26 | % MAT-files required: none 27 | % 28 | % See also: 29 | 30 | % Author: Ivan Brkan 31 | % Written: 23-April-2019 32 | % Last update: 29-April-2019 33 | % Last revision:--- 34 | 35 | %------------- BEGIN CODE -------------- 36 | 37 | switch styleOfCalculation 38 | case 0 39 | % case of truncated Taylor series 40 | result = taylorSeries(intMat,maxOrder); 41 | case 1 42 | % case of truncated Taylor series using horner scheme 43 | result = hornerTaylorSeries(intMat,maxOrder); 44 | case 2 45 | % case of truncated Taylor series using horner scheme and the 46 | 47 | switch length(varargin) 48 | case 0 49 | % no poetntial was given as attribute, 50 | % so 1 is used as the default value 51 | result = scalingSquaringHornerTaylorSeries(intMat,maxOrder,1); 52 | case 1 53 | tmp = cell2mat(varargin); 54 | result = scalingSquaringHornerTaylorSeries(intMat,maxOrder,tmp(1)); 55 | otherwise 56 | result = []; 57 | end 58 | 59 | 60 | otherwise 61 | result = []; 62 | end 63 | 64 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/expmVertex.m: -------------------------------------------------------------------------------- 1 | function eI = expmVertex(intMat) 2 | % expmVertex - computes the exponential matrix for the vertices of the 3 | % interval matrix 4 | % 5 | % Syntax: 6 | % eI = expmVertex(intMat) 7 | % 8 | % Inputs: 9 | % intMat - interval matrix 10 | % 11 | % Outputs: 12 | % eI - interval matrix exponential 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: ---end+i 21 | 22 | % Author: Matthias Althoff 23 | % Written: 02-July-2010 24 | % Last update: --- 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | 30 | %compute vertices 31 | V = dominantVertices(intMat, 100); 32 | 33 | %compute exponential matrices 34 | for i=1:length(V) 35 | eI{i} = expm(V{i}); 36 | end 37 | 38 | 39 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/exponentialRemainder.m: -------------------------------------------------------------------------------- 1 | function E = exponentialRemainder(intMat,maxOrder) 2 | % exponentialRemainder - returns the remainder of the exponential matrix 3 | % 4 | % Syntax: 5 | % E = exponentialRemainder(intMat,maxOrder) 6 | % 7 | % Inputs: 8 | % intMat - interval matrix 9 | % maxOrder - maximum order of Taylor series 10 | % 11 | % Outputs: 12 | % E - remainder of exponential 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: 21 | 22 | % Author: Matthias Althoff 23 | % Written: 18-June-2010 24 | % Last update: 14-November-2018 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | %compute absolute value bound 30 | M = abs(intMat); 31 | 32 | %compute exponential matrix 33 | eM = expm(M); 34 | 35 | % no value is infinity 36 | if ~any(any(isnan(eM))) 37 | 38 | %compute first Taylor terms 39 | Mpow = eye(intMat.dim); 40 | eMpartial = eye(intMat.dim); 41 | for i=1:maxOrder 42 | Mpow = M*Mpow; 43 | eMpartial = eMpartial + Mpow/factorial(i); 44 | end 45 | 46 | W = eM-eMpartial; 47 | 48 | %instantiate remainder 49 | E = intervalMatrix(zeros(intMat.dim),W); 50 | else 51 | %instantiate remainder 52 | E = intervalMatrix(zeros(intMat.dim),inf*ones(intMat.dim)); 53 | end 54 | 55 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/interval.m: -------------------------------------------------------------------------------- 1 | function Int = interval(matI) 2 | % interval - Converts an interval matrix to an interval vector 3 | % 4 | % Syntax: 5 | % Int = interval(matI) 6 | % 7 | % Inputs: 8 | % matI - interval matrix 9 | % 10 | % Outputs: 11 | % Int - interval hull 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: vertices, polytope 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: --- 20 | 21 | % Author: Matthias Althoff 22 | % Written: 21-June-2010 23 | % Last update: 25-July-2016 (intervalhull replaced by interval) 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %convert matrix limits 29 | leftLimit = mat2vec(infimum(matI.int)); 30 | rightLimit = mat2vec(supremum(matI.int)); 31 | 32 | %instantiate interval hull (using MPT toolbox) 33 | Int=interval(leftLimit,rightLimit); 34 | 35 | 36 | 37 | 38 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/intervalMatrix.m: -------------------------------------------------------------------------------- 1 | classdef (InferiorClasses = {?mp}) intervalMatrix 2 | % intervalMatrix class 3 | % 4 | % Syntax: 5 | % obj = intervalMatrix(C,D) 6 | % obj = intervalMatrix(C,D,setting) 7 | % 8 | % Inputs: 9 | % C - center matrix 10 | % D - width matrix 11 | % setting - setting for multiplication ('sharpivmult' or 'standard') 12 | % 13 | % Outputs: 14 | % obj - generated object 15 | % 16 | % Example: 17 | % C = [0 2; 3 1]; 18 | % D = [1 2; 1 1]; 19 | % 20 | % mi = intervalMatrix(C,D); 21 | % 22 | % Other m-files required: none 23 | % Subfunctions: none 24 | % MAT-files required: none 25 | % 26 | % See also: interval, polytope 27 | 28 | % Author: Matthias Althoff 29 | % Written: 18-June-2010 30 | % Last update: 26-August-2011 31 | % 15-June-2016 32 | % Last revision:--- 33 | 34 | %------------- BEGIN CODE -------------- 35 | 36 | properties (SetAccess = private, GetAccess = public) 37 | dim = 1; 38 | Inf = []; 39 | Sup = []; 40 | int = []; 41 | setting = 'sharpivmult'; 42 | end 43 | 44 | methods 45 | %class constructor 46 | function obj = intervalMatrix(matrixCenter,matrixDelta,setting) 47 | 48 | %one input 49 | if nargin==1 50 | if isa(matrixCenter,'intervalMatrix') 51 | obj = matrixCenter; 52 | else 53 | obj.dim = length(matrixCenter); 54 | obj.Inf = matrixCenter; 55 | obj.Sup = matrixCenter; 56 | obj.int = interval(matrixCenter,matrixCenter); 57 | obj.setting = []; 58 | end 59 | elseif nargin==2 60 | obj.dim = length(matrixCenter); 61 | %ensure positive matrix deltas 62 | matrixDelta=abs(matrixDelta); 63 | obj.Inf = matrixCenter-matrixDelta; 64 | obj.Sup = matrixCenter+matrixDelta; 65 | obj.int=interval(obj.Inf,obj.Sup); 66 | obj.setting = []; 67 | elseif nargin==3 68 | obj.dim = length(matrixCenter); 69 | %ensure positive matrix deltas 70 | matrixDelta=abs(matrixDelta); 71 | obj.Inf = matrixCenter-matrixDelta; 72 | obj.Sup = matrixCenter+matrixDelta; 73 | obj.int=interval(obj.Inf,obj.Sup); 74 | obj.setting = setting; %settings: 'sharpivmult','fastivmult' 75 | end 76 | end 77 | 78 | %methods in seperate files 79 | intMat = plus(summand1,summand2) 80 | intMat = mtimes(factor1,factor2) 81 | intMat = mpower(intMat,exponent) 82 | intMat = powers(varargin) 83 | [eI, iPow, E] = expm(varargin) 84 | [eI, iPow, E] = expmInd(varargin) 85 | [eI,eI2,iPow,iPow2,E] = expmMixed(matI,r,intermediateOrder,maxOrder) 86 | [eI,eI2,iPow,iPow2,E] = expmIndMixed(matI,intermediateOrder,maxOrder) 87 | M = abs(intMat) 88 | n = infNorm(intMat) 89 | E = exponentialRemainder(intMat,maxOrder) 90 | IH = interval(intMat) 91 | V = vertices(intMat) 92 | matV = dominantVertices(matI, maxNumber) 93 | matP = matPolytope(intMat) 94 | matZ = matZonotope(intMat) 95 | A = randomSampling(intMat,varargin) 96 | dist = expmDist(intMat,exactMat,maxOrder) 97 | vol = volume(matI) 98 | val = expmNorm(intMat,t) 99 | val = expmNormInf(intMat,t) 100 | absBound = expmAbsoluteBound(intMat,t) 101 | normBoundErr = expmNormErr(intMat,r) 102 | normBoundErr = expmNormErrInf(intMat,r) 103 | eI = expmVertex(intMat) 104 | element = subsref(intMat, S) 105 | sq = exactSquare(A) 106 | res = norm(obj, varargin) 107 | 108 | %display functions 109 | plot(varargin) 110 | display(obj) 111 | end 112 | end 113 | 114 | %------------- END OF CODE ------- -------------------------------------------------------------------------------- /@intervalMatrix/logRemainder.m: -------------------------------------------------------------------------------- 1 | function E = logRemainder(intMat,maxOrder,maxabs) 2 | %there is a problem in this file which is 3 | %compute absolute value bound 4 | % M = abs(intMat); 5 | % %next line problem 6 | % M = logm(M); 7 | M = maxabs; 8 | %compute exponential matrix 9 | eM =expm(M); 10 | 11 | % no value is infinity 12 | if ~any(any(isnan(eM))) 13 | 14 | %compute first Taylor terms 15 | Mpow = eye(intMat.dim); 16 | eMpartial = eye(intMat.dim); 17 | for i=1:maxOrder 18 | Mpow = M*Mpow; 19 | eMpartial = eMpartial + Mpow/factorial(i); 20 | end 21 | 22 | W = eM-eMpartial; 23 | 24 | %instantiate remainder 25 | E = intervalMatrix(zeros(intMat.dim),W); 26 | else 27 | %instantiate remainder 28 | E = intervalMatrix(zeros(intMat.dim),inf*ones(intMat.dim)); 29 | end 30 | 31 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/matPolytope.m: -------------------------------------------------------------------------------- 1 | function matP = matPolytope(matI) 2 | % matPolytopes - converts an interval matrix to a matrix polytope 3 | % 4 | % Syntax: 5 | % matP = matPolytope(matI) 6 | % 7 | % Inputs: 8 | % matI - interval matrix 9 | % 10 | % Outputs: 11 | % matP - polytope matrix 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: plus 20 | 21 | % Author: Matthias Althoff 22 | % Written: 21-June-2010 23 | % Last update: --- 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %obtain vertices 29 | V = dominantVertices(matI,inf); 30 | 31 | %instantiate matrix polytope 32 | matP=matPolytope(V); 33 | 34 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/matZonotope.m: -------------------------------------------------------------------------------- 1 | function matZ = matZonotope(matI) 2 | % matZonotopes - converts an interval matrix to a matrix zonotope 3 | % 4 | % Syntax: 5 | % matZ = matZonotope(matI) 6 | % 7 | % Inputs: 8 | % matI - interval matrix 9 | % 10 | % Outputs: 11 | % matZ - zonotope matrix 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: plus 20 | 21 | % Author: Matthias Althoff 22 | % Written: 21-June-2010 23 | % Last update: 25-July-2016 (intervalhull replaced by interval) 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | % obtain center 28 | % c = center(matI); 29 | % 30 | % % construct generator matrix G 31 | % G = diag(rad(matI)); 32 | % 33 | % % instantiate zonotope 34 | % Z = matZonotope(Z,6); 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | % %convert to interval 37 | temp = matI.int; 38 | col = size(temp.sup,2); 39 | I=interval(matI); 40 | 41 | %convert to zonotope 42 | Z=zonotope(I); 43 | Z=deleteZeros(Z); %delete zero generators 44 | 45 | %convert to matrix zonotope 46 | matZ=matZonotopeConv(Z,col);%6 47 | 48 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/mpower.m: -------------------------------------------------------------------------------- 1 | function intMatPower = mpower(intMat,exponent) 2 | % mpower - Overloaded '^' operator for the power of an interval matrix 3 | % 4 | % Syntax: 5 | % intMatPower = mpower(intMat,exponent) 6 | % 7 | % Inputs: 8 | % intMat - interval matrix 9 | % exponent - exponent 10 | % 11 | % Outputs: 12 | % intMatPower - interval matrix 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 21-June-2010 24 | % Last update: 05-August-2010 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | %factor1 is a numeric matrix 30 | if exponent>=0 31 | if exponent==0 32 | %return identity matrix 33 | intMatPower=intMat; 34 | intMatPower.int=intMat.int^0; 35 | elseif exponent==1 36 | %do nothing 37 | intMatPower=intMat; 38 | else 39 | intMatPower=intMat*intMat; 40 | for i=3:exponent 41 | %multiply matrix zonotope with itself 42 | intMatPower=intMatPower*intMat; 43 | end 44 | end 45 | 46 | else 47 | error('no negative powers supported') 48 | end 49 | 50 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/mtimes.m: -------------------------------------------------------------------------------- 1 | function intMat = mtimes(factor1,factor2) 2 | % mtimes - Overloaded '*' operator for the multiplication of matrix or an 3 | % interval matrix with an interval matrix 4 | % 5 | % Syntax: 6 | % intMat = mtimes(factor1,factor2) 7 | % 8 | % Inputs: 9 | % factor1 - numerical matrix or interval matrix 10 | % factor2 - numerical matrix or interval matrix 11 | % 12 | % Outputs: 13 | % intMatZ - interval matrix 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: plus 22 | 23 | % Author: Matthias Althoff 24 | % Written: 18-June-2010 25 | % Last update: 05-August-2010 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %set multiplication scheme 31 | if isnumeric(factor1) 32 | if ~isempty(factor2.setting) 33 | intvalinit(factor2.setting); 34 | end 35 | else 36 | if ~isempty(factor1.setting) 37 | intvalinit(factor1.setting); 38 | end 39 | end 40 | 41 | %factor1 is a numeric matrix 42 | if isnumeric(factor1) 43 | %initialize factor 44 | matrix=factor1; 45 | %initialize matrix zonotope 46 | intMat=factor2; 47 | %compute new intervals 48 | intMat.int=matrix*intMat.int; 49 | 50 | 51 | %factor2 is a numeric matrix 52 | elseif isnumeric(factor2) 53 | %initialize factor 54 | matrix=factor2; 55 | %initialize matrix zonotope 56 | intMat=factor1; 57 | %compute new intervals 58 | intMat.int=intMat.int*matrix; 59 | 60 | %both factors are interval matrices 61 | else 62 | %initialize matrix zonotope 63 | intMat=factor1; 64 | %compute interval matrix 65 | intMat.int=factor1.int*factor2.int; 66 | end 67 | 68 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/norm.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/@intervalMatrix/norm.m -------------------------------------------------------------------------------- /@intervalMatrix/plot.m: -------------------------------------------------------------------------------- 1 | function plot(varargin) 2 | % plot - Plots 2-dimensional projection of an interval matrix 3 | % 4 | % Syntax: 5 | % plot(obj,dimensions) 6 | % 7 | % Inputs: 8 | % obj - interval matrix 9 | % dimensions - dimensions that should be projected (optional) 10 | % 11 | % Outputs: 12 | % none 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: none 21 | 22 | % Author: Matthias Althoff 23 | % Written: 22-June-2010 24 | % Last update: 25-July-2016 (intervalhull replaced by interval) 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | %convert to interval matrix to interval 30 | IH=interval(varargin{1}); 31 | 32 | %plot interval 33 | if nargin==1 34 | plot(IH); 35 | elseif nargin>=2 36 | plot(IH,varargin{2:end}); 37 | end 38 | 39 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/plus.m: -------------------------------------------------------------------------------- 1 | function intMat = plus(summand1,summand2) 2 | % plus - Overloaded '+' operator for the Minkowski addition of two 3 | % interval matrices or a interval matrix with a matrix 4 | % 5 | % Syntax: 6 | % intMat = plus(summand1,summand2) 7 | % 8 | % Inputs: 9 | % summand1 - interval matrix object or numerical matrix 10 | % summand2 - interval matrix object or numerical matrix 11 | % 12 | % Outputs: 13 | % intMat - interval matrix after Minkowsi addition 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: mtimes 22 | 23 | % Author: Matthias Althoff 24 | % Written: 18-June-2010 25 | % Last update: 05-August-2010 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %Find a matrix zonotope object 31 | %Is summand1 a matrix zonotope? 32 | if isa(summand1,'intervalMatrix') 33 | %initialize resulting zonotope 34 | intMat=summand1; 35 | %initialize other summand 36 | summand=summand2; 37 | %Is summand2 a matrix zonotope? 38 | elseif isa(summand2,'intervalMatrix') 39 | %initialize resulting zonotope 40 | intMat=summand2; 41 | %initialize other summand 42 | summand=summand1; 43 | end 44 | 45 | %Is summand an interval matrix? 46 | if isa(summand,'intervalMatrix') 47 | %Calculate minkowski sum 48 | intMat.int = intMat.int + summand.int; 49 | 50 | %is summand a vector? 51 | elseif isnumeric(summand) 52 | %Calculate minkowski sum 53 | intMat.int = intMat.int + summand; 54 | % %amr 55 | % intMat.Sup = intMat.Sup + summand; 56 | % intMat.Inf = intMat.Inf + summand; 57 | end 58 | 59 | 60 | %------------- END OF CODE -------------- 61 | 62 | 63 | -------------------------------------------------------------------------------- /@intervalMatrix/powers.m: -------------------------------------------------------------------------------- 1 | function pow = powers(varargin) 2 | % powers - computes the powers of an interval matrix 3 | % 4 | % Syntax: 5 | % [intMat] = powers(varargin) 6 | % 7 | % Inputs: 8 | % intMat - interval matrix 9 | % maxOrder - maximum Taylor series order until remainder is computed 10 | % initialOrder - first Taylor series order 11 | % initialPower - initial power for mixed computations 12 | % 13 | % Outputs: 14 | % eI - interval matrix exponential 15 | % 16 | % Example: 17 | % 18 | % Other m-files required: none 19 | % Subfunctions: none 20 | % MAT-files required: none 21 | % 22 | % See also: plus 23 | 24 | % Author: Matthias Althoff 25 | % Written: 18-June-2010 26 | % Last update: 06-July-2010 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | if nargin==2 32 | intMat = varargin{1}; 33 | maxOrder = varargin{2}; 34 | initialOrder = 1; 35 | initialPower = intMat; 36 | elseif nargin==4 37 | intMat = varargin{1}; 38 | maxOrder = varargin{2}; 39 | initialOrder = varargin{3}; 40 | initialPower = varargin{4}; 41 | end 42 | 43 | %initialize power 44 | pow{initialOrder}=initialPower; 45 | 46 | %compute powers 47 | for i=(initialOrder+1):maxOrder 48 | pow{i} = pow{i-1}*intMat; 49 | end 50 | 51 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/private/hornerTaylorSeries.m: -------------------------------------------------------------------------------- 1 | function horner = hornerTaylorSeries(intMat,maxOrder) 2 | % returns the approximation of e^intMat using the horner scheme evaluation 3 | % of the taylorSeries and the 4 | % 5 | % Syntax: 6 | % val = hornerTaylorSeries(intMat,t) 7 | % 8 | % Inputs: 9 | % intMat - interval matrix (nxn) 10 | % maxOrder - maximum order of the TaylorSeries, has to be > abs(intMat) +2 11 | % 12 | % Outputs: 13 | % taylor - the exponentiation with hornerScheme evaluation of the truncated Taylor-Series 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: intervalMatrixRemainder.m 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: 22 | 23 | % Author: Ivan Brkan 24 | % Written: 14-April-2019 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %get norm and size of the matrix 31 | alpha = norm(intMat,inf); 32 | 33 | 34 | n = length(intMat.int.sup); 35 | % maxOrder has to be alpha +2 in order to calculate a solution 36 | if(maxOrder +2 <= alpha) 37 | horner = []; 38 | return; 39 | end 40 | 41 | E = eye(n); 42 | % the algorithm calculates the solution starting at the innermost term, 43 | % so it uses maxOrder first and finishes with 1, as factor the startpoint 44 | horner = plus(E,mtimes(intMat,maxOrder^-1)); 45 | for i= 1:maxOrder-1 46 | horner = plus (E, mtimes((maxOrder-i)^-1, mtimes(intMat,horner)) ); 47 | end 48 | 49 | % Remainder has to be added on the solution, in order to minimize the error 50 | horner = plus(horner, intervalMatrixRemainder(intMat,alpha,maxOrder)); 51 | 52 | -------------------------------------------------------------------------------- /@intervalMatrix/private/intervalMatrixRemainder.m: -------------------------------------------------------------------------------- 1 | function E = intervalMatrixRemainder(intMatr,matrixNorm,maxOrder) 2 | % function, which calculates the remainder for the exponantiation of an 3 | % intervalMatrix depending on the order of the series 4 | % 5 | % Syntax: 6 | % E = intervalMatrixRemainder(intMatr,maxOrder) 7 | % 8 | % Inputs: 9 | % intMatrix - intervalMatrix 10 | % maxOrder - maximum Taylor series order 11 | % 12 | % Outputs 13 | % E = matrix or intervalMatrix with the remainder for the 14 | % exponentiation of an intervalMatrix 15 | % 16 | % Example: 17 | % 18 | % Other m-files required: none 19 | % Subfunctions: none 20 | % MAT-files required: none 21 | 22 | % Author: Ivan Brkan 23 | % Written: 03-April-2019 24 | % Last update: --- 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | % Compute the norm 30 | % a = norm(intMatr,inf); 31 | % getting E started, depending if intMatrix.sup == intMatrix.inf 32 | % it will be [1;1] or [-1;1] 33 | 34 | a = matrixNorm; 35 | n= length(intMatr.int.sup); 36 | 37 | if(isequal(intMatr.int.sup,intMatr.int.inf)) 38 | E=intervalMatrix(ones(n),0); 39 | % a= norm(intMatr.int.sup,inf); 40 | else 41 | E= intervalMatrix(zeros(n),ones(n)); 42 | % a= norm(intMatr,inf); 43 | end 44 | 45 | if(a>=maxOrder+2) 46 | E = []; 47 | return; 48 | end 49 | % no value is infinity .from exponentialRemainder.m 50 | 51 | %if ( ~any(any(isnan(intMatr.int.inf))) && ~any(any(isnan(intMatr.int.sup))) ) 52 | 53 | %compute fomula p(a,K)= a^(K+1)/((K+1)!(1-a/(K+2))) 54 | %factor = a^(maxOrder+1) / ( factorial(maxOrder+1)*(1-(a /(maxOrder+2))) ); 55 | %factor = double( sym(a)^(maxOrder+1) / (factorial(sym(maxOrder +1))*(1-(a/(maxOrder+2))) )); 56 | 57 | increasedOrder = floor(maxOrder)+1; 58 | counter = a*ones(1,(increasedOrder)); 59 | denominator = 1:(increasedOrder); 60 | tmp = counter ./ denominator; 61 | %tmp = tmp(~(tmp==0)); 62 | factor = prod(tmp); 63 | factor = factor / (1-(a/(maxOrder+2))); 64 | 65 | E= E*factor; 66 | 67 | %else 68 | %instantiate remainder - from exponentialRemainder.m 69 | %E = []; 70 | %end 71 | 72 | end 73 | 74 | -------------------------------------------------------------------------------- /@intervalMatrix/private/scalingSquaringHornerTaylorSeries.m: -------------------------------------------------------------------------------- 1 | function scaling = scalingSquaringHornerTaylorSeries(intMat,maxOrder,potentiation) 2 | % returns the approximation of e^intMat using different algorithms 3 | % with maxOrder iterations. It is used as an fassade to access the 4 | % algorithms in the private directory 5 | % 6 | % Syntax: 7 | % scaling = scalingSquaringHornerTaylorSeries(intMat,maxOrder,potentiation) 8 | % 9 | % Inputs: 10 | % intMat - intervalMatrix (nxn) 11 | % maxOrder - maximum order of the TaylorSeries, has to be > abs(intMat) +2 12 | % potentiation - #nodef 13 | % 14 | % Outputs: 15 | % scaling - the exponentiation with the chosen algorithm 16 | % 17 | % Example: 18 | % 19 | % Other m-files required: hornerTaylorSeries.m,taylorSeries.m, intervalMatrixRemainder.m 20 | % Subfunctions: none 21 | % MAT-files required: none 22 | % 23 | % See also: 24 | 25 | % Author: Ivan Brkan 26 | % Written: 23-April-2019 27 | % Last update: --- 28 | % Last revision:--- 29 | 30 | %------------- BEGIN CODE -------------- 31 | 32 | potential = 2^potentiation; 33 | if((maxOrder+2)*potential<=norm(intMat,inf)) 34 | scaling= []; 35 | else 36 | scaling = mpower(hornerTaylorSeries(mtimes(intMat,potential^-1),maxOrder), potential); 37 | end 38 | 39 | -------------------------------------------------------------------------------- /@intervalMatrix/private/taylorSeries.m: -------------------------------------------------------------------------------- 1 | function taylor = taylorSeries(intMat, maxOrder) 2 | % returns the approximation of e^intMat using the truncated Taylor series 3 | % with maxOrder iterations. 4 | % 5 | % Syntax: 6 | % val = taylorSeries(intMat,maxOrder) 7 | % 8 | % Inputs: 9 | % intMat - interval matrix (nxn) 10 | % maxOrder - maximum order of the TaylorSeries, has to be > abs(intMat)+2 11 | % 12 | % Outputs: 13 | % taylor - the exponentiation with the truncated Taylor series 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: intervalMatrixRemainder.m 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: 22 | 23 | % Author: Ivan Brkan 24 | % Written: 06-April-2019 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %get norm and size of the matrix 31 | % needs to be symbolic otherwise it's impossible to calculate the result, 32 | % since the factorials are to big and the some parts of the series are to 33 | % small - inf and 0 are the result 34 | 35 | % alpha = norm(intMat); 36 | % if(isequal(intMat.int.sup,intMat.int.inf)) 37 | % alpha = norm(intMat.int.sup,inf); 38 | % else 39 | alpha = norm(intMat,inf); 40 | % end 41 | n = length(intMat.int.sup); 42 | % if k is not large enough, the error will be to large 43 | 44 | if(maxOrder+2 <= alpha) 45 | taylor = []; 46 | return; 47 | end 48 | 49 | % preparation for the calculation 50 | taylor = zeros(n); 51 | pow = eye(n); 52 | 53 | % the calculation of the Taylor series 54 | for i=1:maxOrder 55 | taylor = plus(taylor,pow); 56 | pow = mtimes(i^-1,mtimes(pow,intMat)); 57 | end 58 | taylor = plus(taylor,pow); 59 | 60 | % Remainder needs to be added on the series to mimizize the error 61 | % watch out, if maxOrder is too low, the result won't be helpful 62 | taylor = plus(taylor, intervalMatrixRemainder(intMat,alpha,maxOrder)); 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /@intervalMatrix/rad.m: -------------------------------------------------------------------------------- 1 | function res = rad(obj) 2 | % rad - returns the radius of an intervalMatrix 3 | % 4 | % Syntax: 5 | % res = rad(obj) 6 | % 7 | % Inputs: 8 | % obj - intervalMatrix object 9 | % 10 | % Outputs: 11 | % res - numerical value (matrix) 12 | % 13 | % Example: 14 | % M = intervalMatrix(eye(2), 2*eye(2)); 15 | % b = rad(M) 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: --- 22 | 23 | % Author: Victor Gassmann 24 | % Written: 23-July-2020 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | res = 0.5*(obj.Sup - obj.Inf); 31 | 32 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@intervalMatrix/randomIntervalMatrix.m: -------------------------------------------------------------------------------- 1 | function intMat = randomIntervalMatrix(center,delta,varyingElements) 2 | % randomIntervalMatrix - generates a random interval matrix with a 3 | % specified center and a specified delta matrix or scalar. The number of 4 | % elements of that matrix which are uncertain has to be specified, too 5 | % 6 | % Syntax: 7 | % intMat = randomIntervalMatrix(center,delta,varyingElements) 8 | % 9 | % Inputs: 10 | % center - center matrix 11 | % delta - delta matrix 12 | % varyingElements - number of elements that may vary 13 | % 14 | % Outputs: 15 | % intMat - interval matrix 16 | % 17 | % Example: 18 | % 19 | % Other m-files required: none 20 | % Subfunctions: none 21 | % MAT-files required: none 22 | % 23 | % See also: plus 24 | 25 | % Author: Matthias Althoff 26 | % Written: 25-June-2010 27 | % Last update: --- 28 | % Last revision:--- 29 | 30 | %------------- BEGIN CODE -------------- 31 | 32 | %determine dimension 33 | dim = length(center); 34 | 35 | %check if varying elements are proper set 36 | if varyingElements>dim^2 37 | varyingElements = dim^2; 38 | end 39 | 40 | %initialize random delta matrix 41 | deltaRand = zeros(dim); 42 | 43 | %obtain uncertain entries of delta 44 | counter = 0; 45 | while counter=2) 61 | ind = combinator(gens,2,'c'); 62 | for i=1:length(ind(:,1)) 63 | sqG{end+1}=(G{ind(i,1)}*G{ind(i,2)} + G{ind(i,2)}*G{ind(i,1)})*r^2; 64 | end 65 | end 66 | %-------------------------------------------------------------------------- 67 | 68 | 69 | %H computation------------------------------------------------------------- 70 | %new center 71 | HC = eye(dim) + C*r + 0.5*sqC; 72 | 73 | %get generators 74 | HG = []; 75 | %1st set of generators 76 | for i=1:gens 77 | HG{end+1}= G{i}*r + 0.5*sqG{i}; 78 | end 79 | %remaining set of generators 80 | for i=(gens+1):length(sqG) 81 | HG{i}=0.5*sqG{i}; 82 | end 83 | %-------------------------------------------------------------------------- 84 | 85 | %write as matrix zonotopes 86 | zSq=matZonotope(sqC,sqG); 87 | zH=matZonotope(HC,HG); 88 | 89 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/display.m: -------------------------------------------------------------------------------- 1 | function display(matZ) 2 | % display - Displays the center and generators of a matrix zonotope 3 | % 4 | % Syntax: 5 | % display(matZ) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope object 9 | % 10 | % Outputs: 11 | % --- 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: none 20 | 21 | % Author: Matthias Althoff 22 | % Written: 18-June-2010 23 | % Last update: --- 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %display dimension, generators 29 | disp('dimension: '); 30 | disp(matZ.dim); 31 | disp('nr of generators: '); 32 | disp(matZ.gens); 33 | %display center 34 | disp('center: '); 35 | disp(matZ.center); 36 | 37 | %display generators 38 | disp('generators: '); 39 | for i=1:length(matZ.generator) 40 | disp(matZ.generator{i}); 41 | disp('---------------'); 42 | end 43 | 44 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/dominantVertices.m: -------------------------------------------------------------------------------- 1 | function matV = dominantVertices(matZ, maxNumber) 2 | % dominantVertices - computes the dominant vertices of a matrix zonotope 3 | % 4 | % Syntax: 5 | % matV = dominantVertices(matZ, maxNumber) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % maxNumber - maximum number of dominant vertices 10 | % 11 | % Outputs: 12 | % matV - cell array of matrix vertices 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 19-July-2010 24 | % Last update: --- 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | %conversion to a zonotope 30 | Z = zonotope(matZ); 31 | 32 | %underapproximate zonotope 33 | V = underapproximate(Z); 34 | 35 | %convert vertices to matrix vertices 36 | for i=1:length(V(1,:)) 37 | matV{i}=vec2mat(V(:,i)); 38 | end 39 | 40 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/expm.m: -------------------------------------------------------------------------------- 1 | function eZ = expm(matZono,varargin) 2 | % expm - operator for the exponential matrix of a matrix zonotope 3 | % 4 | % Syntax: 5 | % eZ = expm(matZono) 6 | % eZ = expm(matZono,maxOrder) 7 | % 8 | % Inputs: 9 | % matZono - matrix zonotope 10 | % maxOrder - maximum Taylor series order until remainder is computed 11 | % 12 | % Outputs: 13 | % eZ - matrix zonotope exponential 14 | % 15 | % Example: 16 | % C = [0 1;0 -2.5]; 17 | % D = [0 0;0 0.5]; 18 | % intMat = intervalMatrix(C,D); 19 | % matZono = matZonotope(intMat); 20 | % 21 | % eZ = expm(matZono) 22 | % 23 | % Other m-files required: none 24 | % Subfunctions: none 25 | % MAT-files required: none 26 | % 27 | % See also: intervalMatrix/expm 28 | 29 | % Author: Niklas Kochdumper 30 | % Written: 26-May-2020 31 | % Last update: --- 32 | % Last revision:--- 33 | 34 | %------------- BEGIN CODE -------------- 35 | 36 | % parse input arguments 37 | maxOrder = 10; 38 | 39 | if nargin > 1 40 | maxOrder = varargin{1}; 41 | end 42 | 43 | % compute matrix exponential 44 | eZ = expmInd(matZono,maxOrder); 45 | 46 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/expmInd.m: -------------------------------------------------------------------------------- 1 | function eZ = expmInd(matZ,maxOrder) 2 | % expmInd - operator for the exponential matrix of a 3 | % matrix zonotope, evaluated independently 4 | % 5 | % Syntax: 6 | % eZ = expmInd(matZ,maxOrder) 7 | % 8 | % Inputs: 9 | % matZ - matrix zonotope 10 | % maxOrder - maximum Taylor series order until remainder is computed 11 | % 12 | % Outputs: 13 | % eZ - matrix zonotope exponential 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: plus 22 | 23 | % Author: Matthias Althoff 24 | % Written: 18-June-2010 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %compute finite Taylor series 31 | %initialize matrix zonotope 32 | eZ=matZ^0; 33 | %initialize power 34 | eZpow=matZ^0; 35 | 36 | %compute finite Taylor sum 37 | for i=1:maxOrder 38 | eZpow = eZpow*matZ; 39 | eZ = eZ + eZpow*(1/factorial(i)); 40 | end 41 | 42 | %compute remainder value 43 | %create over-approximating interval matrix 44 | intMat = intervalMatrix(matZ); 45 | %compute remainder value 46 | E = exponentialRemainder(intMat,maxOrder); 47 | 48 | %convert remainder and add it to the Taylor series 49 | eZ = eZ + matZonotope(E); 50 | 51 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/expmIndMixed.m: -------------------------------------------------------------------------------- 1 | function [eZ,eI,zPow,iPow,E] = expmIndMixed(matZ,intermediateOrder,maxOrder) 2 | % expmIndMixed - operator for the exponential matrix of a 3 | % matrix zonotope, evaluated independently. Higher order terms are computed 4 | % via interval arithmetic. 5 | % 6 | % Syntax: 7 | % [eZ,eI,zPow,iPow,E] = expmIndMixed(matZ,intermediateOrder,maxOrder) 8 | % 9 | % Inputs: 10 | % matZ - matrix zonotope 11 | % intermediate Order - Taylor series order until computation is 12 | % performed with matrix zonotopes 13 | % maxOrder - maximum Taylor series order until remainder is computed 14 | % 15 | % Outputs: 16 | % eZ - matrix zonotope exponential part 17 | % eI - interval matrix exponential part 18 | % zPow - #nodef 19 | % iPow - cell array storing the powers of the matrix: 20 | % A,A^2,...,A^(intermediateOrder) 21 | % E - interval matrix for the remainder 22 | % 23 | % Example: 24 | % 25 | % Other m-files required: none 26 | % Subfunctions: none 27 | % MAT-files required: none 28 | % 29 | % See also: plus 30 | 31 | % Author: Matthias Althoff 32 | % Written: 18-June-2010 33 | % Last update: 05-August-2010 34 | % Last revision:--- 35 | 36 | %------------- BEGIN CODE -------------- 37 | 38 | %compute powers 39 | zPow=powers(matZ,intermediateOrder); 40 | 41 | %compute finite Taylor series 42 | %initialize matrix zonotope 43 | eZ=matZ^0; 44 | 45 | %compute finite Taylor sum 46 | for i=1:intermediateOrder 47 | eZ = eZ + zPow{i}*(1/factorial(i)); 48 | end 49 | 50 | %compute interval part 51 | intMat = intervalMatrix(matZ); 52 | [eI,iPow,E] = expmInd(intMat, maxOrder, intermediateOrder+1, intMat*intervalMatrix(zPow{intermediateOrder})); 53 | 54 | 55 | 56 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/expmMixed.m: -------------------------------------------------------------------------------- 1 | function [eZ,eI,zPow,iPow,E] = expmMixed(matZ,r,intermediateOrder,maxOrder) 2 | % expmMixed - operator for the exponential matrix of a 3 | % matrix zonotope, evaluated dependently. Higher order terms are computed 4 | % via interval arithmetic. 5 | % 6 | % Syntax: 7 | % [eZ,eI,zPow,iPow,E] = expmMixed(matZ,r,intermediateOrder,maxOrder) 8 | % 9 | % Inputs: 10 | % matZ - matrix zonotope 11 | % r - time increment 12 | % intermediate Order - Taylor series order until computation is 13 | % performed with matrix zonotopes 14 | % maxOrder - maximum Taylor series order until remainder is computed 15 | % 16 | % Outputs: 17 | % eZ - matrix zonotope exponential part 18 | % eI - interval matrix exponential part 19 | % 20 | % Example: 21 | % 22 | % Other m-files required: none 23 | % Subfunctions: none 24 | % MAT-files required: none 25 | % 26 | % See also: plus 27 | 28 | % Author: Matthias Althoff 29 | % Written: 13-September-2010 30 | % Last update: --- 31 | % Last revision:--- 32 | 33 | %------------- BEGIN CODE -------------- 34 | 35 | if (intermediateOrder>=2) 36 | 37 | %compute exact terms 38 | [sq,H] = dependentTerms(matZ*(1/r),r); 39 | 40 | %init eZ 41 | eZ = H; 42 | 43 | %compute powers 44 | zPow=powers(matZ,intermediateOrder,2,sq); 45 | 46 | %add first power for input computations 47 | zPow{1}=matZ; 48 | 49 | %compute finite Taylor sum 50 | for i=3:intermediateOrder 51 | eZ = eZ + zPow{i}*(1/factorial(i)); 52 | end 53 | 54 | %compute interval part 55 | matI = intervalMatrix(matZ); 56 | [eI,iPow,E] = expm(matI, r, maxOrder, intermediateOrder+1, matI*intervalMatrix(zPow{intermediateOrder})); 57 | 58 | else 59 | disp('intermediate order too low'); 60 | end 61 | 62 | 63 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/expmOneParam.m: -------------------------------------------------------------------------------- 1 | function [eZ,eI,zPow,iPow,E,RconstInput] = expmOneParam(matZ,r,maxOrder,varargin) 2 | % expmMixed - operator for the exponential matrix of a 3 | % matrix zonotope, evaluated dependently. Higher order terms are computed 4 | % via interval arithmetic. 5 | % 6 | % Syntax: 7 | % [eZ,eI,zPow,iPow,E,RconstInput] = expmOneParam(matZ,r,maxOrder,varargin) 8 | % 9 | % Inputs: 10 | % matZ - matrix zonotope 11 | % r - time increment 12 | % intermediate Order - Taylor series order until computation is 13 | % performed with matrix zonotopes 14 | % maxOrder - maximum Taylor series order until remainder is computed 15 | % options - options struct 16 | % 17 | % Outputs: 18 | % eZ - matrix zonotope exponential part 19 | % eI - interval matrix exponential part 20 | % zPow - #nodef 21 | % iPow - cell array storing the powers of the matrix: 22 | % A,A^2,...,A^(intermediateOrder) 23 | % E - interval matrix for the remainder 24 | % RconstInput - #nodef 25 | % 26 | % Example: 27 | % 28 | % Other m-files required: none 29 | % Subfunctions: none 30 | % MAT-files required: none 31 | % 32 | % See also: plus 33 | 34 | % Author: Matthias Althoff 35 | % Written: 13-September-2010 36 | % Last update: 04-April-2017 37 | % Last revision:--- 38 | 39 | %------------- BEGIN CODE -------------- 40 | 41 | %cannot directly use u as input since zonotope has preference over 42 | %matZonotopes 43 | if length(varargin) == 1 44 | options = varargin{1}; 45 | if ~isa(options.uTrans,'zonotope') 46 | u = zonotope([options.uTrans,zeros(size(options.uTrans))]); 47 | else 48 | u = zonotope(options.uTrans); 49 | end 50 | else 51 | u = zonotope([0,0]); 52 | end 53 | 54 | %obatin matrix center and generator 55 | C = matZ.center; 56 | G = matZ.generator{1}; 57 | 58 | %obtain center and generator of input uTrans 59 | u_mat = u.Z; 60 | c_u = u_mat(:,1); 61 | g_u = u_mat(:,2); 62 | 63 | %initialize matrices D,E (center and generators of powers) 64 | D{1} = C; 65 | E{1}{1} = G; 66 | 67 | D_u{1} = c_u; 68 | E_u{1}{1} = g_u; 69 | 70 | %update power cell 71 | zPow{1} = matZ*r; 72 | 73 | %the first cell index refers to the power! 74 | for n = 2:maxOrder 75 | D{n} = D{n-1}*C; 76 | E{n}{1} = D{n-1}*G + E{n-1}{1}*C; 77 | for i = 2:(n-1) 78 | E{n}{i} = E{n-1}{i-1}*G + E{n-1}{i}*C; 79 | end 80 | E{n}{n} = E{n-1}{n-1}*G; 81 | 82 | %input 83 | D_u{n} = D{n-1}*c_u; 84 | E_u{n}{1} = D{n-1}*g_u + E{n-1}{1}*c_u; 85 | for i = 2:(n-1) 86 | E_u{n}{i} = E{n-1}{i-1}*g_u + E{n-1}{i}*c_u; 87 | end 88 | E_u{n}{n} = E{n-1}{n-1}*g_u; 89 | 90 | %update power cell 91 | zPow{n} = matZonotope(D{n},E{n})*r^n; 92 | end 93 | 94 | %compute exponential matrix 95 | %generators 96 | for n = 1:maxOrder 97 | factor = r^n/factorial(n); 98 | E_sum{n} = E{n}{1}*factor; 99 | E_u_sum{n} = E_u{n}{1}*factor; 100 | for i=(n+1):maxOrder 101 | factor = r^i/factorial(i); 102 | E_sum{n} = E_sum{n} + E{i}{n}*factor; 103 | E_u_sum{n} = E_u_sum{n} + E_u{i}{n}*factor; 104 | end 105 | end 106 | 107 | %center 108 | D_sum = eye(matZ.dim) + D{1}*r; 109 | D_u_sum = D_u{1}*r; 110 | for i = 2:maxOrder 111 | factor = r^i/factorial(i); 112 | D_sum = D_sum + D{i}*factor; 113 | D_u_sum = D_u_sum + D_u{i}*factor; 114 | end 115 | 116 | %reduce size of generators for even numbers and add to center 117 | for n = 1:floor(maxOrder/2) 118 | E_sum{2*n} = 0.5*E_sum{2*n}; 119 | D_sum = D_sum + E_sum{2*n}; 120 | 121 | E_u_sum{2*n} = 0.5*E_u_sum{2*n}; 122 | D_u_sum = D_u_sum + E_u_sum{2*n}; 123 | end 124 | 125 | %compute remainder 126 | matI = intervalMatrix(matZ*r); 127 | E = exponentialRemainder( matI,maxOrder); 128 | 129 | %write result to eZ and eI 130 | eZ = matZonotope(D_sum, E_sum); 131 | eI = E; 132 | 133 | %obtain constant input zonotope 134 | RconstInput = zonotope(matZonotope(D_u_sum, E_u_sum)); 135 | %RconstInput = zonotope(D_u_sum, E_u_sum); 136 | 137 | 138 | iPow = []; %no powers based on interval matrix 139 | 140 | 141 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/expmVertex.m: -------------------------------------------------------------------------------- 1 | function eZ = expmVertex(matZ) 2 | % expmVertex - computes the exponential matrix for the vertices of the 3 | % matrix zonotope 4 | % 5 | % Syntax: 6 | % eZ = expmVertex(matZ) 7 | % 8 | % Inputs: 9 | % matZ - matrix zonotope 10 | % 11 | % Outputs: 12 | % eZ - matrix zonotope exponential 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: ---end+i 21 | 22 | % Author: Matthias Althoff 23 | % Written: 19-July-2010 24 | % Last update: --- 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | 30 | %compute vertices 31 | V = dominantVertices(matZ, 100); 32 | 33 | %compute exponential matrices 34 | for i=1:length(V) 35 | eZ{i} = expm(V{i}); 36 | end 37 | 38 | 39 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/intervalMatrix.m: -------------------------------------------------------------------------------- 1 | function matI = intervalMatrix(varargin) 2 | % intervalMatrix - computes an enclosing interval matrix of a matrix 3 | % zonotope 4 | % 5 | % Syntax: 6 | % matI = intervalMatrix(matZ) 7 | % 8 | % Inputs: 9 | % matZ - matrix zonotope 10 | % 11 | % Outputs: 12 | % matI - intervalMatrix 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 21-June-2010 24 | % Last update: 06-October-2010 25 | % 26-August-2011 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | if nargin==1 31 | matZ=varargin{1}; 32 | setting=[]; 33 | elseif nargin==2 34 | matZ=varargin{1}; 35 | setting=varargin{2}; 36 | end 37 | 38 | %delta 39 | delta = abs(matZ.generator{1}); 40 | for i=2:matZ.gens 41 | delta = delta + abs(matZ.generator{i}); 42 | 43 | end 44 | 45 | %instantiate interval matrix 46 | matI = intervalMatrix(matZ.center, delta, setting); 47 | 48 | 49 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/matPolytope.m: -------------------------------------------------------------------------------- 1 | function matP = matPolytope(matZ) 2 | % matPolytope - Converts a matrix zonotope into a matrix polytope 3 | % representation 4 | % 5 | % Syntax: 6 | % matP = matPolytope(matZ) 7 | % 8 | % Inputs: 9 | % matZ - matrix zonotope 10 | % 11 | % Outputs: 12 | % matP - matrix polytope 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: vertices, polytope 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: --- 21 | 22 | % Author: Matthias Althoff 23 | % Written: 22-June-2010 24 | % Last update: --- 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | % obtain vertices 30 | V=vertices(zonotope(matZ)); 31 | 32 | %obtain vertices 33 | for i=1:length(V(1,:)) 34 | matrixVertex{i}=vec2mat(V(:,i)); 35 | end 36 | 37 | %convert polytope to matrix polytope 38 | matP=matPolytope(matrixVertex); 39 | 40 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/matZonotope.m: -------------------------------------------------------------------------------- 1 | classdef (InferiorClasses = {?mp}) matZonotope 2 | % matZonotope class 3 | % 4 | % Syntax: 5 | % obj = matZonotope(C,G) 6 | % 7 | % Inputs: 8 | % C - center matrix 9 | % G - cell-array storing the generator matrices 10 | % 11 | % Outputs: 12 | % obj - generated object 13 | % 14 | % Example: 15 | % C = [0 0; 0 0]; 16 | % G{1} = [1 3; -1 2]; 17 | % G{2} = [2 0; 1 -1]; 18 | % 19 | % mz = matZonotope(C,G); 20 | % 21 | % Other m-files required: none 22 | % Subfunctions: none 23 | % MAT-files required: none 24 | % 25 | % See also: intervalMatrix, matPolytope 26 | 27 | % Author: Matthias Althoff 28 | % Written: 14-September-2006 29 | % Last update: 22-March-2007 30 | % 04-June-2010 31 | % 27-Aug-2019 32 | % Last revision: --- 33 | 34 | %------------- BEGIN CODE -------------- 35 | 36 | properties (SetAccess = private, GetAccess = public) 37 | dim = 1; 38 | gens = 0; 39 | center = 0; 40 | generator = []; 41 | end 42 | 43 | methods 44 | 45 | % class constructor 46 | function obj = matZonotope(input1,input2) 47 | %one input 48 | if nargin==0 49 | matrixCenter = 0; 50 | matrixGenerator = []; 51 | elseif nargin==1 52 | if isa(input1,'zonotope') 53 | %extract center 54 | c=center(input1); 55 | %extract generator matrix 56 | G=generators(input1); 57 | %obtain matrix center 58 | matrixCenter = vec2mat(c); 59 | %obtain matrix generators 60 | if ~isempty(G) 61 | for i=1:length(G(1,:)) 62 | matrixGenerator{i}=vec2mat(G(:,i)); 63 | end 64 | else 65 | matrixGenerator{1} = zeros(size(matrixCenter)); 66 | end 67 | else 68 | matrixCenter=input1; 69 | matrixGenerator = []; 70 | end 71 | elseif nargin==2 72 | matrixCenter = input1; 73 | matrixGenerator = input2; 74 | end 75 | %set parameters 76 | obj.dim = length(matrixCenter); 77 | obj.gens = length(matrixGenerator); 78 | obj.center = matrixCenter; 79 | obj.generator = matrixGenerator; 80 | end 81 | 82 | %methods in seperate files 83 | matZ = plus(summand1,summand2) 84 | matZ = mtimes(factor1,factor2) 85 | matZ = mpower(matZ,exponent) 86 | matZ = powers(varargin) 87 | matZ = expmInd(matZ,maxOrder) 88 | [eZ,eI,zPow,iPow,E] = expmMixed(matZ,r,intermediateOrder,maxOrder) 89 | [eZ,eI,zPow,iPow,E] = expmIndMixed(matZ,intermediateOrder,maxOrder) 90 | [eZ,eI,zPow,iPow,E,RconstInput] = expmOneParam(matZ,r,maxOrder,u) 91 | intMat = intervalMatrix(varargin) 92 | matZ = zonotope(matZ) 93 | dist = expmDist(matZ,intMat,maxOrder) 94 | matZred = reduce(matZ,option,order,filterLength) 95 | vol = volume(matI) 96 | matZ1 = concatenate(matZ1,matZ2) 97 | res = norm(obj, varargin) 98 | newObj = subsref(obj, S) 99 | 100 | %display functions 101 | plot(varargin) 102 | display(obj) 103 | 104 | end 105 | end 106 | 107 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/mpower.m: -------------------------------------------------------------------------------- 1 | function matZpower = mpower(matZ,exponent) 2 | % mpower - Overloaded '^' operator for the power of matrix zonotope 3 | % 4 | % Syntax: 5 | % matZ = mpower(matZ,exponent) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % exponent - exponent 10 | % 11 | % Outputs: 12 | % matZ - matrix zonotope 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 18-June-2010 24 | % Last update: 05-August-2010 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | %factor1 is a numeric matrix 30 | if exponent>=0 31 | if exponent==0 32 | %return identity matrix 33 | matZpower=matZ; 34 | matZpower.center=eye(matZ.dim); 35 | matZpower.generator=[]; 36 | matZpower.gens=0; 37 | elseif exponent==1 38 | %do nothing 39 | matZpower=matZ; 40 | else 41 | matZpower=matZ*matZ; 42 | for i=3:exponent 43 | %multiply matrix zonotope with itself 44 | matZpower=matZpower*matZ; 45 | end 46 | end 47 | else 48 | matZpower=[]; 49 | disp('no negative powers supported') 50 | end 51 | 52 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/mtimes.m: -------------------------------------------------------------------------------- 1 | function matZ = mtimes(factor1,factor2) 2 | % mtimes - Overloaded '*' operator for the multiplication of a matrix or a 3 | % matrix zonotope with a matrix zonotope 4 | % 5 | % Syntax: 6 | % matZ = mtimes(factor1,factor2) 7 | % 8 | % Inputs: 9 | % factor1 - numerical matrix or matrix zonotope 10 | % factor2 - numerical matrix or matrix zonotope 11 | % 12 | % Outputs: 13 | % matZ - matrix zonotope 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: plus 22 | 23 | % Author: Matthias Althoff 24 | % Written: 18-June-2010 25 | % Last update: 05-August-2010 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %factor1 is a numeric matrix 31 | if isnumeric(factor1) 32 | %initialize factor 33 | matrix=factor1; 34 | %initialize matrix zonotope 35 | matZ=factor2; 36 | %compute center 37 | matZ.center=matrix*matZ.center; 38 | for i=1:matZ.gens 39 | matZ.generator{i}=matrix*matZ.generator{i}; 40 | end 41 | 42 | %factor2 is a numeric matrix 43 | elseif isnumeric(factor2) 44 | %initialize factor 45 | matrix=factor2; 46 | %initialize matrix zonotope 47 | matZ=factor1; 48 | %compute center 49 | matZ.center=matZ.center*matrix; 50 | for i=1:matZ.gens 51 | matZ.generator{i}=matZ.generator{i}*matrix; 52 | end 53 | 54 | %both factors are zonotope matrices 55 | else 56 | %initialize matrix zonotope 57 | matZ1=factor1; 58 | %initialize matrix zonotope 59 | matZ2=factor2; 60 | %initialize matrix zonotope 61 | matZ=matZonotope(); 62 | %compute center 63 | matZ.center=matZ1.center*matZ2.center; 64 | %compute generators 65 | %center1 with generators2 66 | for i=1:matZ2.gens 67 | matZ.generator{end+1}=matZ1.center*matZ2.generator{i}; 68 | end 69 | %generator1 with center2 70 | for i=1:matZ1.gens 71 | matZ.generator{end+1}=matZ1.generator{i}*matZ2.center; 72 | end 73 | %generators1 with generators2 74 | for j=1:matZ1.gens 75 | for i=1:matZ2.gens 76 | matZ.generator{end+1}=matZ1.generator{j}*matZ2.generator{i}; 77 | end 78 | end 79 | %update number of generators and dimension 80 | matZ.dim=matZ.dim; 81 | matZ.gens=(matZ1.gens+1)*(matZ2.gens+1)-1; 82 | end 83 | 84 | 85 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/norm.m: -------------------------------------------------------------------------------- 1 | function res = norm(obj, varargin) 2 | % norm - computes approximately the maximum norm value of all possible matrices 3 | % 4 | % Syntax: 5 | % res = norm(obj, varargin) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % varargin - list of optional inputs 10 | % 11 | % Outputs: 12 | % res - resulting maximum norm value 13 | % 14 | % Example: 15 | % --- 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: @zonotope/norm 22 | 23 | % Author: Matthias Althoff, Victor Gassmann 24 | % Written: 02-November-2017 25 | % Last update: 23-July-2020 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | M = intervalMatrix(obj); 31 | res = norm(M,varargin{:}); 32 | 33 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/plot.m: -------------------------------------------------------------------------------- 1 | function plot(varargin) 2 | % plot - Plots 2-dimensional projection of a matrix zonotope 3 | % 4 | % Syntax: 5 | % plot(obj,dimensions) 6 | % 7 | % Inputs: 8 | % obj - matrix zonotope 9 | % dimensions - dimensions that should be projected (optional) 10 | % linespec - plot style (optional) 11 | % 12 | % Outputs: 13 | % none 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: none 22 | 23 | % Author: Matthias Althoff 24 | % Written: 22-June-2010 25 | % Last update: --- 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %convert from matrix zonotope to zonotope 31 | Z=zonotope(varargin{1}); 32 | 33 | %plot zonotope 34 | if nargin==1 35 | plot(Z); 36 | elseif nargin==2 37 | plot(Z,varargin{2}); 38 | else 39 | plot(Z,varargin{2},varargin{3}); 40 | end 41 | 42 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/plus.m: -------------------------------------------------------------------------------- 1 | function matZ = plus(summand1,summand2) 2 | % plus - Overloaded '+' operator for the Minkowski addition of two 3 | % matrix zonotopes or a matrix zonotope with a matrix 4 | % 5 | % Syntax: 6 | % [matZ] = plus(summand1,summand2) 7 | % 8 | % Inputs: 9 | % summand1 - zonotope matrix object or numerical matrix 10 | % summand2 - zonotope matrix object or numerical matrix 11 | % 12 | % Outputs: 13 | % matZ - matrix zonotpe after Minkowsi addition 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: mtimes 22 | 23 | % Author: Matthias Althoff 24 | % Written: 18-June-2010 25 | % Last update: 05-August-2010 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | %Find a matrix zonotope object 31 | %Is summand1 a matrix zonotope? 32 | if isa(summand1,'matZonotope') 33 | %initialize resulting zonotope 34 | matZ=summand1; 35 | %initialize other summand 36 | summand=summand2; 37 | %Is summand2 a matrix zonotope? 38 | elseif isa(summand2,'matZonotope') 39 | %initialize resulting zonotope 40 | matZ=summand2; 41 | %initialize other summand 42 | summand=summand1; 43 | end 44 | 45 | %Is summand a zonotope? 46 | if isa(summand,'matZonotope') 47 | %Calculate minkowski sum 48 | matZ.center = matZ.center + summand.center; 49 | 50 | if isempty(matZ.generator) 51 | %concatenate matrix generators 52 | matZ.generator = summand.generator; 53 | else 54 | %concatenate matrix generators 55 | matZ.generator((end+1):(end+summand.gens)) = summand.generator; 56 | end 57 | %update number of generators 58 | matZ.gens=matZ.gens + summand.gens; 59 | 60 | %is summand a vector? 61 | elseif isnumeric(summand) 62 | %Calculate minkowski sum 63 | matZ.center = matZ.center + summand; 64 | end 65 | 66 | 67 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/powers.m: -------------------------------------------------------------------------------- 1 | function pow = powers(varargin) 2 | % powers - computes the powers of a matrix zonotope 3 | % 4 | % Syntax: 5 | % matZ = powers(matZ,maxOrder) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % maxOrder - maximum Taylor series order until remainder is computed 10 | % 11 | % Outputs: 12 | % matZ - matrix zonotope 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 05-August-2010 24 | % Last update: 24-September-2010 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | if nargin==2 30 | matZ = varargin{1}; 31 | maxOrder = varargin{2}; 32 | initialOrder = 1; 33 | initialPower = matZ; 34 | elseif nargin==4 35 | matZ = varargin{1}; 36 | maxOrder = varargin{2}; 37 | initialOrder = varargin{3}; 38 | initialPower = varargin{4}; 39 | end 40 | 41 | %initialize power 42 | pow{initialOrder}=initialPower; 43 | 44 | %compute powers 45 | for i=(initialOrder+1):maxOrder 46 | pow{i} = pow{i-1}*matZ; 47 | end 48 | 49 | 50 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/randomSampling.m: -------------------------------------------------------------------------------- 1 | function A = randomSampling(matZ,varargin) 2 | % randomSampling - creates random samples within a matrix zonotope 3 | % 4 | % Syntax: 5 | % A = randomSampling(matZ,samples) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % samples - number of segments 10 | % options - options struct 11 | % 12 | % Outputs: 13 | % A - cell array of matrices 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: none 22 | 23 | % Author: Matthias Althoff 24 | % Written: 23-June-2010 25 | % Last update: 02-April-2017 26 | % Last revision:--- 27 | 28 | %------------- BEGIN CODE -------------- 29 | 30 | % set default inputs 31 | if nargin == 1 32 | samples = 1; 33 | extreme = 1; 34 | elseif nargin == 2 35 | samples = varargin{1}; 36 | extreme = 1; 37 | else 38 | samples = varargin{1}; 39 | options = varargin{2}; 40 | if isfield(options,'extremeSampling') 41 | extreme = options.extremeSampling; 42 | else 43 | extreme = 1; 44 | end 45 | end 46 | 47 | % generate sample matrices 48 | A=cell(samples,1); 49 | for i=1:samples 50 | %initialize random matrix 51 | A{i}=matZ.center; 52 | %add generator matrices 53 | for iGen=1:matZ.gens 54 | if extreme 55 | A{i}=A{i} + sign(2*rand(1)-1).*matZ.generator{iGen}; 56 | else 57 | A{i}=A{i} + (2*rand(1)-1).*matZ.generator{iGen}; 58 | end 59 | end 60 | end 61 | 62 | %------------- END OF CODE -------------- 63 | %------------- END OF CODE -------------- 64 | -------------------------------------------------------------------------------- /@matZonotope/reduce.m: -------------------------------------------------------------------------------- 1 | function matZred = reduce(matZ,option,order,filterLength) 2 | % reduce - Reduces the order of a matrix zonotope 3 | % This is done by converting the matrix zonotope to a zonotope 4 | % 5 | % Syntax: 6 | % matZred = reduce(matZ,option,order) 7 | % 8 | % Inputs: 9 | % matZ - matrix zonotope 10 | % option - selects the reduction method 11 | % order - order of reduced zonotope 12 | % filterLength - #nodef 13 | % 14 | % Outputs: 15 | % matZred - reduced matrix zonotope 16 | % 17 | % Example: 18 | % 19 | % Other m-files required: none 20 | % Subfunctions: 21 | % MAT-files required: none 22 | % 23 | % See also: none 24 | 25 | % Author: Matthias Althoff 26 | % Written: 24-June-2010 27 | % Last update: --- 28 | % Last revision:--- 29 | 30 | %------------- BEGIN CODE -------------- 31 | 32 | %convert matrix zonotope to zonotope 33 | noOfCol = size(matZ.center,2); 34 | Z=zonotope(matZ); 35 | filterLength =1; 36 | %reduce zonotope 37 | Zred = reduce(Z, option, order, filterLength); 38 | 39 | %convert back to matrix zonotope 40 | matZred = matZonotope(Zred,noOfCol); 41 | 42 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/subsref.m: -------------------------------------------------------------------------------- 1 | function newObj = subsref(obj, S) 2 | % subsref - Overloads the opertor that selects elements, e.g. I(1,2), 3 | % where the element of the first row and second column is referred to. 4 | % 5 | % Syntax: 6 | % newObj = subsref(obj, S) 7 | % 8 | % Inputs: 9 | % obj - matrix zonotope object 10 | % S - contains information of the type and content of element selections 11 | % 12 | % Outputs: 13 | % newObj - matrix zonotope object 14 | % 15 | % Example: 16 | % C = rand(3); 17 | % G{1} = rand(3); 18 | % matZ = matZonotope(C, G); 19 | % matZ(1,2) 20 | % 21 | % Other m-files required: none 22 | % Subfunctions: none 23 | % MAT-files required: none 24 | % 25 | % See also: none 26 | 27 | % Author: Matthias Althoff, Niklas Kochdumper 28 | % Written: 09-November-2018 29 | % Last update: 12-November-2018 (NK: default to build in for other cases) 30 | % Last revision:--- 31 | 32 | %------------- BEGIN CODE -------------- 33 | 34 | %check if parantheses are used to select elements 35 | if length(S) == 1 && strcmp(S.type,'()') 36 | 37 | %obtain sub-intervals from the interval object 38 | newObj = obj; 39 | 40 | % only one index specified 41 | if length(S.subs)==1 42 | newObj.center = obj.center(S.subs{1}); 43 | for iGen = 1:newObj.gens 44 | newObj.generator{iGen} = obj.generator{iGen}(S.subs{1}); 45 | end 46 | %two indices specified 47 | elseif length(S.subs)==2 48 | %Select column of obj 49 | if strcmp(S.subs{1},':') 50 | column = S.subs{2}; 51 | newObj.center = obj.center(:,column); 52 | for iGen = 1:newObj.gens 53 | newObj.generator{iGen} = obj.generator{iGen}(:,column); 54 | end 55 | %Select row of V 56 | elseif strcmp(S.subs{2},':') 57 | row = S.subs{1}; 58 | newObj.center = obj.center(row,:); 59 | for iGen = 1:newObj.gens 60 | newObj.generator{iGen} = obj.generator{iGen}(row,:); 61 | end 62 | %Select single element of V 63 | elseif isnumeric(S.subs{1}) && isnumeric(S.subs{1}) 64 | row = S.subs{1}; 65 | column = S.subs{2}; 66 | newObj.center = obj.center(row,column); 67 | for iGen = 1:newObj.gens 68 | newObj.generator{iGen} = obj.generator{iGen}(row,column); 69 | end 70 | end 71 | end 72 | else 73 | % call build in subsref function as a default 74 | newObj = builtin('subsref', obj, S); 75 | end 76 | 77 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/vertices.m: -------------------------------------------------------------------------------- 1 | function matV = vertices(matZ) 2 | % vertices - computes the vertices of a matrix zonotope 3 | % 4 | % Syntax: 5 | % matV = vertices(matZ) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % 10 | % Outputs: 11 | % matV - cell array of matrix vertices 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: plus 20 | 21 | % Author: Matthias Althoff 22 | % Written: 24-June-2010 23 | % Last update: --- 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %conversion to an intervalhull 29 | Z = zonotope(matZ); 30 | 31 | %compute vertices 32 | V = vertices(Z,'polytope'); 33 | V = unique(V', 'rows')'; %eliminate vectors that occur multiple times 34 | 35 | %convert vertices to matrix vertices 36 | matV=cell(length(V(1,:)),1); 37 | for i=1:length(V(1,:)) 38 | matV{i}=vec2mat(V(:,i)); 39 | end 40 | 41 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/volume.m: -------------------------------------------------------------------------------- 1 | function vol = volume(matZ) 2 | % volume - computes the volume of a matrix zonotope by computing the volume 3 | % of the corresponding zonotope 4 | % 5 | % Syntax: 6 | % vol = volume(matZ) 7 | % 8 | % Inputs: 9 | % matZ - matrix zonotope 10 | % 11 | % Outputs: 12 | % vol - volume 13 | % 14 | % Example: 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: plus 21 | 22 | % Author: Matthias Althoff 23 | % Written: 24-June-2010 24 | % Last update: --- 25 | % Last revision:--- 26 | 27 | %------------- BEGIN CODE -------------- 28 | 29 | %conversion to a zonotope 30 | Z = zonotope(matZ); 31 | 32 | %compute volume of the zonotope 33 | vol = volume(Z); 34 | 35 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@matZonotope/zonotope.m: -------------------------------------------------------------------------------- 1 | function Z = zonotope(matZ) 2 | % zonotope - Converts a matrix zonotope into a zonotope 3 | % 4 | % Syntax: 5 | % Z = zonotope(matZ) 6 | % 7 | % Inputs: 8 | % matZ - matrix zonotope 9 | % 10 | % Outputs: 11 | % Z - zonotope 12 | % 13 | % Example: 14 | % 15 | % Other m-files required: none 16 | % Subfunctions: none 17 | % MAT-files required: none 18 | % 19 | % See also: plus 20 | 21 | % Author: Matthias Althoff 22 | % Written: 18-June-2010 23 | % Last update: --- 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | 28 | %concert center 29 | center=mat2vec(matZ.center); 30 | 31 | %convert generators 32 | for i=1:matZ.gens 33 | generatorMatrix(:,i) = mat2vec(matZ.generator{i}); 34 | end 35 | 36 | %instantiate zonotope 37 | Z=zonotope([center,generatorMatrix]); 38 | 39 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@nonlinearDT/checkOptionsReach.m: -------------------------------------------------------------------------------- 1 | function options = checkOptionsReach(obj,options,hyb) 2 | % checkOptionsReach - checks if all necessary options 3 | % are there and have valid values 4 | % 5 | % Syntax: 6 | % options = checkOptionsReach(obj,options,hyb) 7 | % 8 | % Inputs: 9 | % obj - linearSys object (unused) 10 | % options - options for linearSys (1x1 struct) 11 | % hyb - if called from hybrid class 12 | % 13 | % Outputs: 14 | % options - options for linearSys (1x1 struct) 15 | % 16 | % Other m-files required: none 17 | % Subfunctions: none 18 | % MAT-files required: none 19 | % 20 | % See also: none 21 | % 22 | % References: 23 | % - 24 | 25 | % Author: Mark Wetzlinger 26 | % Written: 05-Feb-2019 27 | % Last update: 03-May-2020 (rewriting of error msgs using class(obj)) 28 | % Last revision:--- 29 | 30 | %------------- BEGIN CODE -------------- 31 | 32 | checkName = 'checkOptionsReach'; 33 | if nargin == 3 34 | suppressWarnings = hyb; 35 | else 36 | suppressWarnings = 0; 37 | end 38 | 39 | % DEFAULT OPTIONS --------------------------------------------------------- 40 | 41 | options = check_tStart_tFinal(obj, options, checkName); 42 | options = check_reductionTechnique(options, obj); 43 | options = check_verbose(options, obj); 44 | check_lagrangeRem(options, obj); 45 | 46 | t = options.tStart:obj.dt:options.tFinal; 47 | if t(end) ~= options.tFinal 48 | error('Final time has to be a multiple of the sampling time!'); 49 | end 50 | 51 | % MANDATORY OPTIONS ------------------------------------------------------- 52 | 53 | check_R0(options, obj); 54 | options = check_inputSet(obj, options); 55 | 56 | % algorithm properties: 57 | 58 | check_zonotopeOrder(options, obj); 59 | 60 | % WARNINGS ---------------------------------------------------------------- 61 | 62 | % do not print warnings if called from HA obj 63 | if ~suppressWarnings 64 | 65 | % warnings for unused options (overdefined) 66 | % validFields = getValidFields(class(obj)); 67 | % warning(printRedundancies(options,validFields)); 68 | 69 | end 70 | 71 | 72 | % INTERNAL SETTINGS ------------------------------------------------------- 73 | 74 | if ~hyb 75 | options = set_inputSet(obj, options, checkName); 76 | end 77 | 78 | end 79 | 80 | %------------- END OF CODE -------------- 81 | 82 | -------------------------------------------------------------------------------- /@nonlinearDT/linError_mixed_noInt_DT.m: -------------------------------------------------------------------------------- 1 | function errorZon = linError_mixed_noInt_DT(obj, options, R) 2 | % linError_mixed_noInt - computes the linearization error 3 | % 4 | % Syntax: 5 | % error = linError_mixed_noInt(obj,options,R) 6 | % 7 | % Inputs: 8 | % obj - nonlinearSysDT system object 9 | % options - options struct 10 | % R - initial set 11 | % 12 | % Outputs: 13 | % errorZon - zonotope overapproximating the linearization error 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: 22 | 23 | % Author: Matthias Althoff, Niklas Kochdumper 24 | % Written: 21-August-2012 25 | % Last update: 25-July-2016 (intervalhull replaced by interval) 26 | % 29-January-2018 (NK) 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | %obtain intervals and combined interval z 32 | dx = interval(R); 33 | du = interval(options.U); 34 | dz = [dx; du]; 35 | 36 | %compute interval of reachable set 37 | totalInt_x = dx + obj.linError.p.x; 38 | 39 | %compute intervals of input 40 | totalInt_u = du + obj.linError.p.u; 41 | 42 | %compute zonotope of state and input 43 | Rred = reduce(R,'girard',options.errorOrder); 44 | Z=cartProd(Rred,options.U); 45 | 46 | %obtain hessian tensor 47 | if isfield(options,'lagrangeRem') && isfield(options.lagrangeRem,'method') && ... 48 | ~strcmp(options.lagrangeRem.method,'interval') 49 | 50 | % create taylor models or zoo-objects 51 | [objX,objU] = initRangeBoundingObjects(totalInt_x,totalInt_u,options); 52 | 53 | % evaluate the hessian tensor 54 | H = obj.hessian(objX,objU); 55 | else 56 | H = obj.hessian(totalInt_x, totalInt_u); 57 | end 58 | 59 | %obtain absolute values 60 | dz_abs = max(abs(infimum(dz)), abs(supremum(dz))); 61 | 62 | %separate evaluation 63 | H_mid = cell(obj.dim,1); 64 | H_rad = cell(obj.dim,1); 65 | for i=1:obj.dim 66 | H_mid{i} = sparse(center(H{i})); 67 | H_rad{i} = sparse(rad(H{i})); 68 | end 69 | 70 | error_mid = 0.5*quadMap(Z, H_mid); 71 | 72 | %interval evaluation 73 | error_rad = zeros(obj.dim,1); 74 | for i=1:obj.dim 75 | error_rad(i,1) = 0.5*dz_abs'*H_rad{i}*dz_abs; 76 | end 77 | 78 | %combine results 79 | error_rad_zono = zonotope(interval(-error_rad, error_rad)); 80 | errorZon = error_mid + error_rad_zono; 81 | 82 | errorZon = reduce(errorZon,options.reductionTechnique,options.zonotopeOrder); 83 | 84 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@nonlinearDT/linReach_DT.m: -------------------------------------------------------------------------------- 1 | function [Rtp ,Rtp_data] = linReach_DT(obj,Rinit,R_data,options) 2 | % linReach - computes the reachable set after linearization 3 | % 4 | % Syntax: 5 | % [Rtp] = linReach_DT(obj,Rinit,options) 6 | % 7 | % Inputs: 8 | % obj - nonlinearSysDT system object 9 | % Rinit - initial reachable set 10 | % options - options struct 11 | % 12 | % Outputs: 13 | % Rtp - resulting reachable set 14 | % 15 | % Example: 16 | % 17 | % Other m-files required: none 18 | % Subfunctions: none 19 | % MAT-files required: none 20 | % 21 | % See also: 22 | 23 | % Author: Amr Alanwar, Matthias Althoff, Niklas Kochdumper 24 | % Written: 21-August-2012 25 | % Last update: 29-January-2018 (NK) 26 | % 29-October-2020 (Amr) add data driven reachability 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | % linearize nonlinear system 32 | [obj,A_lin,U] = linearize_DT(obj,Rinit,options); 33 | 34 | %translate Rinit by linearization point 35 | Rdelta = Rinit + (-obj.linError.p.x); 36 | 37 | % compute reachable set of linearized system 38 | Rtp = A_lin*Rdelta + U; 39 | 40 | % obtain linearization error 41 | if options.tensorOrder > 2 42 | Verror = linError_thirdOrder(obj, options, Rdelta); 43 | else 44 | Verror = linError_mixed_noInt_DT(obj, options, Rdelta); 45 | end 46 | 47 | 48 | %add interval of actual error 49 | Rtp=Rtp+Verror+options.W; 50 | % %%%%%%%%-------------------Data driven reachability----------- 51 | options.Uorig= options.U + options.uTrans; 52 | xStar = R_data.center; 53 | uStar =options.Uorig.center; 54 | xStarMat = repmat(xStar,1,size(options.X_0T,2)); 55 | uStarMat = repmat(uStar,1,size(options.U_full,2)); 56 | oneMat = repmat([1],1,size(options.U_full,2)); 57 | IAB = (options.X_1T )*pinv([oneMat; options.X_0T+(-1*xStarMat);options.U_full+-1*uStarMat]); 58 | 59 | V = options.X_1T + -1*(IAB*[oneMat; options.X_0T+(-1*xStarMat);options.U_full+-1*uStarMat] + options.Wmatzono); 60 | VInt = intervalMatrix(V); 61 | leftLimit = VInt.Inf; 62 | rightLimit = VInt.Sup; 63 | 64 | V_one= zonotope(interval(min(leftLimit')',max(rightLimit')')); 65 | 66 | 67 | 68 | Rtp_data = IAB*cartProd([1],cartProd(R_data+(-1*xStar),options.Uorig+(-1*uStar))) +V_one+ options.W ; 69 | 70 | 71 | 72 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@nonlinearDT/linearize_DT.m: -------------------------------------------------------------------------------- 1 | function [obj,A_lin,U] = linearize_DT(obj,R,options) 2 | % linearize - linearizes the nonlinearSysDT object 3 | % 4 | % Syntax: 5 | % [obj,A_lin,U] = linearize(obj,R,options) 6 | % 7 | % Inputs: 8 | % obj - nonlinearSysDT system object 9 | % R - initial reachable set 10 | % options - options struct 11 | % 12 | % Outputs: 13 | % obj - nonlinearSysDT system object with additional properties 14 | % A_lin - system matrix of the linearized system 15 | % U - reachable set due to the inputs 16 | % 17 | % Example: 18 | % Text for example... 19 | % 20 | % Other m-files required: none 21 | % Subfunctions: none 22 | % MAT-files required: none 23 | % 24 | % See also: 25 | 26 | % Author: Matthias Althoff, Niklas Kochdumper 27 | % Written: 21-August-2012 28 | % Last update: 29-January-2018 29 | % Last revision:--- 30 | 31 | %------------- BEGIN CODE -------------- 32 | 33 | %linearization point p.u of the input is the center of the input u 34 | p.u = center(options.U) + options.uTrans; 35 | 36 | %linearization point p.x and p.y 37 | x0 = center(R); 38 | p.x = x0; 39 | 40 | %substitute p into the system equation in order to obtain the constant 41 | %input 42 | f0 = obj.mFile(p.x, p.u); 43 | 44 | %get jacobian matrices 45 | [A_lin,B_lin] = obj.jacobian(p.x, p.u); 46 | 47 | 48 | uTrans = f0; %B*Ucenter from linOptions.U not added as the system is linearized around center(U) 49 | Udelta = B_lin*(options.U+(-center(options.U))); 50 | U = Udelta + uTrans; 51 | 52 | %save linearization point 53 | obj.linError.p=p; 54 | 55 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@nonlinearDT/nonlinearDT.m: -------------------------------------------------------------------------------- 1 | classdef nonlinearDT < contDynamics 2 | % nonlinearSysDT class (time-discrete nonlinear system) 3 | % 4 | % Syntax: 5 | % obj = nonlinearSysDT(fun,dt) 6 | % obj = nonlinearSysDT(name,fun,dt) 7 | % obj = nonlinearSysDT(fun,dt,states,inputs) 8 | % obj = nonlinearSysDT(name,fun,dt,states,inputs) 9 | % 10 | % Inputs: 11 | % fun - function handle to the dynamic equation 12 | % name - name of dynamics 13 | % dt - sampling time 14 | % states - number of states 15 | % inputs - number of inputs 16 | % 17 | % Outputs: 18 | % obj - Generated Object 19 | % 20 | % Example: 21 | % f = @(x,u) [x(1) + u(1);x(2) + u(2)*cos(x(1));x(3) + u(2)*sin(x(1))]; 22 | % dt = 0.25; 23 | % sys = nonlinearSysDT(f,dt) 24 | % 25 | % Other m-files required: none 26 | % Subfunctions: none 27 | % MAT-files required: none 28 | % 29 | % See also: linearSysDT 30 | 31 | % Author: Matthias Althoff, Niklas Kochdumper 32 | % Written: 21-August-2012 33 | % Last update: 29-January-2018 34 | % 20-March-2020 (MA, simulate random removed, now provided by inherinted class) 35 | % 19-May-2020 (NK, changed constructor syntax) 36 | % Last revision:--- 37 | 38 | %------------- BEGIN CODE -------------- 39 | 40 | 41 | properties (SetAccess = private, GetAccess = public) 42 | mFile = []; % function handle dynamic equation 43 | jacobian = []; % function handle jacobian matrix 44 | hessian = []; % function handle hessian tensor 45 | thirdOrderTensor = []; % function handle third-order tensor 46 | linError = []; 47 | dt = []; % sampling time 48 | end 49 | 50 | methods 51 | 52 | % class constructor 53 | function obj = nonlinearDT(varargin) 54 | 55 | name = []; states = []; inputs = []; 56 | 57 | % parse input arguments 58 | if nargin == 2 59 | fun = varargin{1}; 60 | dt = varargin{2}; 61 | elseif nargin == 3 62 | name = varargin{1}; 63 | fun = varargin{2}; 64 | dt = varargin{3}; 65 | elseif nargin == 4 66 | fun = varargin{1}; 67 | dt = varargin{2}; 68 | states = varargin{3}; 69 | inputs = varargin{4}; 70 | elseif nargin == 5 71 | name = varargin{1}; 72 | fun = varargin{2}; 73 | dt = varargin{3}; 74 | states = varargin{4}; 75 | inputs = varargin{5}; 76 | else 77 | error('Wrong number of input arguments!'); 78 | end 79 | 80 | % get name from function handle 81 | if isempty(name) 82 | name = func2str(fun); 83 | name = strrep(name,'@',''); 84 | name = strrep(name,'(',''); 85 | name = strrep(name,')',''); 86 | name = strrep(name,',',''); 87 | if ~isvarname(name) 88 | name = 'nonlinearSysDT'; 89 | end 90 | end 91 | 92 | % get number of states and number of inputs 93 | if isempty(states) || isempty(inputs) 94 | try 95 | temp = numberOfInputs(fun,2); 96 | 97 | states = temp(1); 98 | inputs = max(1,temp(2)); 99 | catch 100 | error(['Failed to determine number of states and ' ... 101 | 'inputs automatically! Please provide number of ' ... 102 | 'states and inputs as additional input arguments!']); 103 | end 104 | end 105 | 106 | % generate parent object 107 | obj@contDynamics(name,states,inputs,1); 108 | 109 | % assign object properties 110 | obj.mFile = fun; 111 | obj.dt = dt; 112 | 113 | str = ['obj.jacobian = @jacobian_',name,';']; 114 | eval(str); 115 | 116 | str = ['obj.hessian = @hessianTensor_',name,';']; 117 | eval(str); 118 | 119 | str = ['obj.thirdOrderTensor = @thirdOrderTensor_',name,';']; 120 | eval(str); 121 | end 122 | end 123 | end 124 | 125 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /@nonlinearDT/reach_DT.m: -------------------------------------------------------------------------------- 1 | function [R ,R_data]= reach_DT(obj,params,options,varargin) 2 | % reach - computes the reachable sets of the discrete time system 3 | % 4 | % Syntax: 5 | % R = reach_DT(obj,params,options) 6 | % [R,res] = reach_DT(obj,params,options,spec) 7 | % 8 | % Inputs: 9 | % obj - nonlinearSysDT object 10 | % params - parameter defining the reachability problem 11 | % options - options for the computation of the reachable set 12 | % spec - object of class specification 13 | % 14 | % Outputs: 15 | % R - object of class reachSet storing the reachable set 16 | % res - 1 if specifications are satisfied, 0 if not 17 | % 18 | % Other m-files required: none 19 | % Subfunctions: none 20 | % MAT-files required: none 21 | % 22 | % See also: nonlinearSysDT 23 | 24 | % Author: Matthias Althoff, Niklas Kochdumper, Amr Alanwar 25 | % Written: 21-August-2012 26 | % Last update: 29-January-2018 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | % options preprocessing 32 | options = params2options(params,options); 33 | options = checkOptionsReach(obj,options,0); 34 | 35 | spec = []; 36 | if nargin >= 4 37 | spec = varargin{1}; 38 | end 39 | 40 | % compute symbolic derivatives 41 | derivatives(obj,options); 42 | 43 | % initialize cell array that stores the reachable sets 44 | t = options.tStart:obj.dt:options.tFinal; 45 | 46 | steps = length(t)-1; 47 | R = cell(steps+1,1); 48 | R_data = cell(steps+1,1); 49 | R{1} = params.R0; 50 | R_data{1} = params.R0; 51 | % loop over all reachablity steps 52 | for i = 1:steps 53 | 54 | % if a trajectory should be tracked 55 | if isfield(options,'uTransVec') 56 | options.uTrans = options.uTransVec(:,i); 57 | end 58 | %reduce 59 | R{i} = reduce(R{i},'girard',20); 60 | R_data{i} = reduce(R_data{i},'girard',100); 61 | % compute next reachable set 62 | [R{i+1},R_data{i+1}] = linReach_DT(obj,R{i},R_data{i},options); 63 | 64 | if isfield(options,'verbose') && options.verbose 65 | disp(t(i)); 66 | end 67 | 68 | % check specification 69 | if ~isempty(spec) 70 | if ~check(spec,R{i+1}) 71 | timePoint.set = R(2:i+1); 72 | timePoint.time = num2cell(t(2:i+1)'); 73 | R = reachSet(timePoint); 74 | return; 75 | end 76 | end 77 | end 78 | 79 | % create reachable set object 80 | timePoint.set = R(2:end); 81 | timePoint.time = num2cell(t(2:end)'); 82 | 83 | timePoint_data.set = R_data(2:end); 84 | timePoint_data.time = num2cell(t(2:end)'); 85 | 86 | R = reachSet(timePoint); 87 | R_data = reachSet(timePoint_data); 88 | end 89 | 90 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /Figures/idea3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/Figures/idea3.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Data Driven Reachability Analysis from Noisy Data 2 |
3 | This repo contains the code for our two papers: 4 | 5 |

6 | 1- Amr Alanwar, Anne Koch, Frank Allgower, Karl Johansson "Data Driven Reachability Analysis using Matrix Zonotopes" 7 | 3rd Annual Learning for Dynamics and Control Conference ( [link](https://arxiv.org/abs/2011.08472) ) 8 | 9 |

10 | 2- Amr Alanwar, Anne Koch, Frank Allgower, Karl Johansson "Data Driven Reachability Analysis from Noisy Data" IEEE Transactions on Automatic Control ( [link](https://ieeexplore.ieee.org/document/10068731) ) 11 | 12 | ## L4DC Short video about the idea 13 | 14 | [![L4DC](https://img.youtube.com/vi/LkV6WqhFsBE/0.jpg)](https://www.youtube.com/watch?v=LkV6WqhFsBE) 15 | 16 | 17 | ## Problem Statement 18 | We consider the problem of reachability analysis from noisy data, given that the system model is unknown. 19 | Identifying a model is a preliminary step in the state-of-the-art reachability analysis approaches. 20 | However, systems are becoming more complex, and data is becoming more readily available. 21 | We propose a data-driven reachability analysis using matrix zonotope and using a new set representation named constrained matrix zonotope.
22 | The following figure summarizes the idea behind our papers. 23 |

24 |

25 | Subject Pronouns 31 |

32 |
33 |
34 | 35 | ## Files Description 36 | There are two levels of complexity for the proposed data driven reachability analysis
37 | A- Basic reachability analysis under the folder examples-basic

38 | B- Advanced reachability analysis using constrained matrix zonotope under the folder examples-cmz. 39 | These files compare three methods for reachability analysis namely, matrix zonotope, constrained matrix 40 | zonotop using exact noise description and constrained matrix zonotope given side information.
41 |
42 | 43 | ## Running 44 | 1- Download [CORA 2020](https://tumcps.github.io/CORA/pages/archive/v2020/index.html) and [MPT](https://www.mpt3.org) toolboxs.
45 | 2- Add CORA and MPT folder and subfolders to the Matlab path.
46 | 3- Add the repo folder and subfolders to the Matlab path.
47 |
48 |
49 | ## Basix reachablity under the folder examples-basic:
50 | 1- run a_linearDT.m for linear system using matrix zonotope.
51 | 2- run a_nonlinearDT.m for nonlinear system.
52 | 3- run a_polyDT.m for polynomial system using matrix zonotope.
53 |
54 |
55 | ## Advanced reachablity under the folder examples-cmz:
56 | 1- run b_linearDT_measnoise.m for linear system with measurement noise.
57 | 2- run b_linearDT_sideInfo.m for linear system given side information.
58 | 3- run b_polyDT_sideInfo.m for polynomial system given side information.
59 |
60 |
61 | You can save the workspace after any advanced reachability file (folder examples-cmz) and then run the plotting 62 | file under the folder plotting.
63 | For example, run
64 | b_linearDT_sideInfo.m
65 | save the workspace and load it later then run
66 | p_plot_linearDT_sideInfo.m
67 |
68 |
69 |
70 |
71 |
72 | Our papers Bibtex are as follow:
73 | ``` 74 | @InProceedings{pmlr-v144-alanwar21a, 75 | title = {Data-Driven Reachability Analysis Using Matrix Zonotopes}, 76 | author = {Alanwar, Amr and Koch, Anne and Allg\"ower, Frank and Johansson, Karl Henrik}, 77 | booktitle ={Proceedings of the 3rd Conference on Learning for Dynamics and Control}, 78 | pages = {163--175}, 79 | year = {2021}, 80 | volume = {144}, 81 | series = {Proceedings of Machine Learning Research}, 82 | month = {07 -- 08 June}, 83 | publisher = {PMLR}, 84 | } 85 | 86 | ``` 87 | 88 | ``` 89 | @ARTICLE{10068731, 90 | author={Alanwar, Amr and Koch, Anne and Allgöwer, Frank and Johansson, Karl Henrik}, 91 | journal={IEEE Transactions on Automatic Control}, 92 | title={Data-Driven Reachability Analysis from Noisy Data}, 93 | year={2023}, 94 | volume={}, 95 | number={}, 96 | pages={1-16}, 97 | doi={10.1109/TAC.2023.3257167}} 98 | ``` 99 | -------------------------------------------------------------------------------- /examples-basic/a_linearDT.m: -------------------------------------------------------------------------------- 1 | % t_linearDT - computes the data driven reachable set of discrete time systems 2 | % x(k+1) = Ax(k) + Bu(k) + w(k) 3 | % 4 | % Example: 5 | % 6 | % Other m-files required: none 7 | % Subfunctions: none 8 | % MAT-files required: none 9 | % 10 | % See also: Amr Alanwar, Anne Koch, Frank Allgöwer, Karl Johansson "Data Driven Reachability Analysis Using Matrix Zonotopes" 11 | % 12 | % 13 | % 14 | % Author: Amr Alanwar 15 | % Written: 28-October-2020 16 | % Last update: 17 | % Last revision:--- 18 | 19 | %------------- BEGIN CODE -------------- 20 | 21 | rand('seed',1); 22 | 23 | clear all 24 | %close all 25 | %% system dynamics 26 | dim_x = 5; 27 | A = [-1 -4 0 0 0; 4 -1 0 0 0; 0 0 -3 1 0; 0 0 -1 -3 0; 0 0 0 0 -2]; 28 | B_ss = ones(5,1); 29 | C = [1,0,0,0,0]; 30 | D = 0; 31 | % define continuous time system 32 | sys_c = ss(A,B_ss,C,D); 33 | % convert to discrete system 34 | samplingtime = 0.05; 35 | sys_d = c2d(sys_c,samplingtime); 36 | 37 | %Number of trajectories 38 | initpoints =1; 39 | %Number of time steps 40 | steps = 120; 41 | totalsamples = initpoints*steps; 42 | %% initial set and input 43 | X0 = zonotope(ones(dim_x,1),0.1*diag(ones(dim_x,1))); 44 | U = zonotope(10,0.25); 45 | 46 | %noise zontope W 47 | W = zonotope(zeros(dim_x,1),0.005*ones(dim_x,1)); 48 | 49 | %Construct matrix zonotpe \mathcal{M}_w 50 | index=1; 51 | for i=1:size(W.generators,2) 52 | vec=W.Z(:,i+1); 53 | GW{index}= [ vec,zeros(dim_x,totalsamples-1)]; 54 | for j=1:totalsamples-1 55 | GW{j+index}= [GW{index+j-1}(:,2:end) GW{index+j-1}(:,1)]; 56 | end 57 | index = j+index+1; 58 | end 59 | Wmatzono= matZonotope(zeros(dim_x,totalsamples),GW); 60 | 61 | 62 | % randomly choose constant inputs for each step / sampling time 63 | for i=1:totalsamples 64 | u(i) = randPoint(U); 65 | end 66 | 67 | 68 | 69 | %simulate the system to get the data 70 | x0 = X0.center; 71 | x(:,1) = x0; 72 | index=1; 73 | for j=1:dim_x:initpoints*dim_x 74 | x(j:j+dim_x-1,1) = randPoint(X0); 75 | for i=1:steps 76 | utraj(j,i) = u(index); 77 | x(j:j+dim_x-1,i+1) = sys_d.A*x(j:j+dim_x-1,i) + sys_d.B*u(index) + randPoint(W); 78 | index=index+1; 79 | end 80 | end 81 | 82 | 83 | % concatenate the data trajectories 84 | index_0 =1; 85 | index_1 =1; 86 | for j=1:dim_x:initpoints*dim_x 87 | for i=2:steps+1 88 | x_meas_vec_1(:,index_1) = x(j:j+dim_x-1,i); 89 | index_1 = index_1 +1; 90 | end 91 | for i=1:steps 92 | u_mean_vec_0(:,index_0) = utraj(j,i); 93 | x_meas_vec_0(:,index_0) = x(j:j+dim_x-1,i); 94 | index_0 = index_0 +1; 95 | end 96 | end 97 | 98 | % X_+ is X_1T 99 | % X_- is X_0T 100 | U_full = u_mean_vec_0(:,1:totalsamples); %same as u 101 | X_0T = x_meas_vec_0(:,1:totalsamples); 102 | X_1T = x_meas_vec_1(:,1:totalsamples); 103 | 104 | 105 | % plot simulated trajectory 106 | figure; 107 | subplot(1,2,1); hold on; box on; plot(x(1,:),x(2,:),'b'); xlabel('x_1'); ylabel('x_2'); 108 | subplot(1,2,2); hold on; box on; plot(x(3,:),x(4,:),'b'); xlabel('x_3'); ylabel('x_4'); 109 | close; 110 | 111 | 112 | 113 | X1W_cen = X_1T - Wmatzono.center; 114 | X1W = matZonotope(X1W_cen,Wmatzono.generator); 115 | 116 | % set of A and B 117 | AB = X1W *pinv([X_0T;U_full]); 118 | 119 | % validate that A and B are within AB 120 | intAB11 = intervalMatrix(AB); 121 | intAB1 = intAB11.int; 122 | intAB1.sup >= [sys_d.A,sys_d.B] 123 | intAB1.inf <= [sys_d.A,sys_d.B] 124 | 125 | 126 | 127 | %% compute next step sets from model / data 128 | 129 | % set number of steps in analysis 130 | totalsteps = 5; 131 | X_model = cell(totalsteps+1,1); 132 | X_data = cell(totalsteps+1,1); 133 | % init sets for loop 134 | X_model{1} = X0; X_data{1} = X0; 135 | 136 | for i=1:totalsteps 137 | 138 | % 1) model-based computation 139 | X_model{i,1}=reduce(X_model{i,1},'girard',400); 140 | X_model{i+1,1} = sys_d.A * X_model{i} + sys_d.B * U+W; 141 | % 2) Data Driven approach 142 | X_data{i,1}=reduce(X_data{i,1},'girard',400); 143 | X_data{i+1,1} = AB * (cartProd(X_data{i},U)) +W; 144 | 145 | 146 | end 147 | 148 | 149 | 150 | 151 | %% visualization 152 | 153 | projectedDims = {[1 2],[3 4],[4 5]}; 154 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 155 | index=1; 156 | numberofplots = 5;%length(X_model) 157 | for plotRun=1:length(projectedDims) 158 | 159 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 160 | 161 | % set axis 162 | 163 | index=index+1; 164 | % plot initial set 165 | handleX0 = plot(X0,projectedDims{plotRun},'k-','LineWidth',2); 166 | hold on; 167 | 168 | 169 | % plot reachable sets starting from index 2, since index 1 = X0 170 | 171 | % plot reachable sets from model 172 | for iSet=2:numberofplots 173 | handleModel= plot(X_model{iSet},projectedDims{plotRun},'b','Filled',true,'FaceColor',[.8 .8 .8],'EdgeColor','b'); 174 | end 175 | 176 | % plot reachable sets from data 177 | for iSet=2:numberofplots 178 | handleData= plot(X_data{iSet},projectedDims{plotRun},'r'); 179 | end 180 | 181 | % label plot 182 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 183 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 184 | %axis(axx{plotRun}); 185 | % skip warning for extra legend entries 186 | warOrig = warning; warning('off','all'); 187 | legend([handleX0,handleModel,handleData],... 188 | 'Initial Set','Set from Model','Set from Data','Location','northwest'); 189 | warning(warOrig); 190 | ax = gca; 191 | ax.FontSize = 22; 192 | %set(gcf, 'Position', [50, 50, 800, 400]) 193 | ax = gca; 194 | outerpos = ax.OuterPosition; 195 | ti = ax.TightInset; 196 | left = outerpos(1) + ti(1); 197 | bottom = outerpos(2) + ti(2); 198 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 199 | ax_height = outerpos(4) - ti(2) - ti(4); 200 | ax.Position = [left bottom ax_width ax_height]; 201 | %set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]); 202 | 203 | end 204 | 205 | 206 | 207 | 208 | 209 | %------------- END OF CODE -------------- 210 | 211 | -------------------------------------------------------------------------------- /examples-basic/a_nonlinearDT.m: -------------------------------------------------------------------------------- 1 | % t_nonlinearDT - computes the data driven reachable set of discrete time systems 2 | % x(k+1) = f(x(k),u(k)) + w(k) 3 | % The approach is based on [1]. The nonlinear system is found in [2] 4 | % 5 | % 6 | % 7 | % Syntax: 8 | % t_nonlinearDT 9 | % 10 | % Inputs: 11 | % no 12 | % 13 | % Outputs: 14 | % no 15 | % 16 | % Example: 17 | % 18 | % References: 19 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer, Karl Johansson 20 | % "Data Driven Reachability Analysis Using Matrix Zonotopes" 21 | % [2] J.M. Bravo, Robust MPC of constrained discrete-time 22 | % nonlinear systems based on approximated reachable sets, 2006 23 | % 24 | % 25 | % Author: Amr Alanwar 26 | % Written: 29-October-2020 27 | % Last update: 28 | % Last revision:--- 29 | 30 | 31 | %------------- BEGIN CODE -------------- 32 | 33 | clear all 34 | close all 35 | %addpath('@nonlinearDT') 36 | rand('seed',1); 37 | dt =0.015; 38 | NN=5; 39 | params.tFinal = dt*NN; 40 | 41 | %input set 42 | params.U = zonotope([[0.01;0.01],diag([0.1;0.2])]); 43 | 44 | %initial set 45 | params.R0 = zonotope([[-1.9;-20],diag([0.005;0.3])]); 46 | % dimension of x 47 | options.dim_x=2; 48 | 49 | %Number of trajectories 50 | initpoints=30; 51 | %Number of time steps 52 | steps=20; 53 | 54 | %Totoal number of samples 55 | totalsamples = steps*initpoints; 56 | 57 | %noise zonotope 58 | wfac = 1e-4; 59 | options.W = zonotope(zeros(options.dim_x,1),wfac*ones(options.dim_x,1)); % disturbance 60 | 61 | %noise matrix zonotope 62 | for i=1:size(options.W.generators,2) 63 | vec=options.W.Z(:,i+1); 64 | for j=0:totalsamples-1 65 | GW{j+i}= [ zeros(options.dim_x,j),vec,zeros(options.dim_x,totalsamples-j-1)]; 66 | end 67 | end 68 | options.Wmatzono= matZonotope(zeros(options.dim_x,totalsamples),GW); 69 | 70 | % Reachability Settings 71 | 72 | options.zonotopeOrder = 100; 73 | options.tensorOrder = 2; 74 | options.errorOrder = 5; 75 | 76 | 77 | % System Dynamics 78 | fun = @(x,u) cstrDiscr(x,u,dt); 79 | 80 | %input random sample points 81 | for i=1:totalsamples 82 | u(:,i) = randPointExtreme(params.U); 83 | end 84 | 85 | %get state trajectories 86 | x(:,1) = randPoint(params.R0); 87 | index=1; 88 | for j=1:options.dim_x:initpoints*options.dim_x 89 | x(j:j+options.dim_x-1,1) = randPoint(params.R0); 90 | x_free(j:j+options.dim_x-1,1) = x(j:j+options.dim_x-1,1); 91 | for i=1:steps 92 | x_free(j:j+options.dim_x-1,i+1) = fun(x(j:j+options.dim_x-1,i),u(:,index)); 93 | x(j:j+options.dim_x-1,i+1) = fun(x(j:j+options.dim_x-1,i),u(:,index)) +randPoint(options.W); 94 | index=index+1; 95 | end 96 | end 97 | 98 | 99 | %combine trajectories 100 | index_0 =1; 101 | index_1 =1; 102 | for j=1:options.dim_x:initpoints*options.dim_x 103 | for i=2:steps+1 104 | x_meas_vec_1(:,index_1) = x(j:j+options.dim_x-1,i); 105 | x_free_vec_1(:,index_1) = x_free(j:j+options.dim_x-1,i); 106 | index_1 = index_1 +1; 107 | end 108 | for i=1:steps 109 | x_free_vec_0(:,index_0) = x_free(j:j+options.dim_x-1,i); 110 | x_meas_vec_0(:,index_0) = x(j:j+options.dim_x-1,i); 111 | index_0 = index_0 +1; 112 | end 113 | end 114 | 115 | stepsLip=1; 116 | initpointsLip=50; 117 | [gamma,L]= compLipConst(fun,params.U,params.R0,stepsLip,initpointsLip,options.dim_x); 118 | 119 | eps(1)= L(1) .* gamma(1)/2; 120 | eps(2)= L(2) .* gamma(2)/2; 121 | %options.Zeps = zonotope([zeros(2,1),eps*diag(ones(2,1))]); 122 | options.Zeps = zonotope([zeros(2,1),diag(eps)]); 123 | % flag to add Zeps 0 to skip, 1 to add the Zeps 124 | options.ZepsFlag = 1; 125 | 126 | % X_+ is X_1T 127 | % X_- is X_0T 128 | options.U_full = u(:,1:totalsamples); 129 | options.X_0T = x_meas_vec_0(:,1:totalsamples); 130 | options.X_1T = x_meas_vec_1(:,1:totalsamples); 131 | 132 | % define system 133 | sysDisc = nonlinearDT('stirredTankReactor',fun,dt,2,2); 134 | 135 | 136 | % Reachability Analysis --------------------------------------------------- 137 | % compute model based reachability (R) and data driven one (R_data) 138 | tic 139 | [R ,R_data]= reach_DT(sysDisc,params,options); 140 | tComp = toc; 141 | disp("Computation time: " + tComp); 142 | 143 | if options.ZepsFlag 144 | for i = 1:NN 145 | R_data.timePoint.set{i} = R_data.timePoint.set{i} + options.Zeps; 146 | end 147 | end 148 | 149 | 150 | % Visualization ----------------------------------------------------------- 151 | 152 | figure; hold on; box on; 153 | 154 | % plot initial set 155 | handleX0=plot(params.R0,[1,2],'k-','LineWidth',2); 156 | 157 | % plot model based reachable set 158 | handleModel=plot(R,[1 2],'b','Filled',true,'FaceColor',[.8 .8 .8],'EdgeColor','b'); 159 | 160 | % plot data driven reachable set 161 | handleData=plot(R_data,[1 2],'r','Filled',false); 162 | 163 | 164 | % formatting 165 | xlabel('x_1'); 166 | ylabel('x_2'); 167 | 168 | % skip warning for extra legend entries 169 | warOrig = warning; warning('off','all'); 170 | legend([handleX0,handleModel,handleData],... 171 | 'Initial set $\mathcal{X}_0$','Set from model $\mathcal{R}_k$','Set from data $\mathcal{R}_k^{\prime}$','Location','northwest','Interpreter','latex'); 172 | warning(warOrig); 173 | ax = gca; 174 | ax.FontSize = 16; 175 | %set(gcf, 'Position', [50, 50, 800, 400]) 176 | ax = gca; 177 | outerpos = ax.OuterPosition; 178 | ti = ax.TightInset; 179 | left = outerpos(1) + ti(1); 180 | bottom = outerpos(2) + ti(2); 181 | ax_width = outerpos(3) - ti(1) - ti(3)-.01; 182 | ax_height = outerpos(4) - ti(2) - ti(4); 183 | ax.Position = [left bottom ax_width ax_height]; 184 | %set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]); 185 | % example completed 186 | completed = 1; 187 | 188 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /examples-basic/a_polyDT.m: -------------------------------------------------------------------------------- 1 | % example_poly - example of reachability analysis for polynomial systems. This example generates the reachable regoins using matrix 2 | % zonotope. 3 | % 4 | % This example can be found in [1]. 5 | % 6 | % Syntax: 7 | % example_sideInfo 8 | % 9 | % Inputs: 10 | % no 11 | % 12 | % Outputs: 13 | % no 14 | % 15 | % References: 16 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer,Karl Henrik Johansson 17 | % "Data-Driven Reachability Analysis from Noisy Data" 18 | % Author: Amr Alanwar 19 | % Written: 17-Jan-2021 20 | % Last update: 21-May-2021 21 | % Last revision:--- 22 | 23 | %------------- BEGIN CODE -------------- 24 | 25 | clear all 26 | close all 27 | rand('seed',1); 28 | 29 | %time steps 30 | N=3; 31 | dt = 0.015; 32 | %final time for model based reachability 33 | params.tFinal = dt*N; 34 | 35 | %input set 36 | params.U = zonotope([[0.2;0.3],diag([0.01,0.02])]); 37 | 38 | %initial set 39 | params.R0 = zonotope([[1;2],diag([0.05;0.3])]); 40 | % dimension of x 41 | options.dim_x=2; 42 | 43 | %Number of trajectories 44 | initpoints=20; 45 | %Number of time steps 46 | steps=7; 47 | 48 | %Totoal number of samples 49 | totalsamples = steps*initpoints; 50 | 51 | %noise zonotope 52 | wfac = 0.00007; 53 | options.W = zonotope(zeros(options.dim_x,1),wfac*ones(options.dim_x,1)); % disturbance 54 | 55 | %noise matrix zonotope 56 | for i=1:size(options.W.generators,2) 57 | vec=options.W.Z(:,i+1); 58 | for j=0:totalsamples-1 59 | GW{j+i}= [ zeros(options.dim_x,j),vec,zeros(options.dim_x,totalsamples-j-1)]; 60 | end 61 | end 62 | Wmatzono= matZonotope(zeros(options.dim_x,totalsamples),GW); 63 | 64 | % Reachability Settings 65 | options.zonotopeOrder = 200; 66 | options.tensorOrder = 2; 67 | options.errorOrder = 5; 68 | 69 | 70 | % True system dynamics 71 | fun = @(x,u) polyFun(x,u,dt); 72 | 73 | %input random sample points 74 | for i=1:totalsamples 75 | u(:,i) = randPoint(params.U); 76 | end 77 | 78 | %get state trajectories 79 | x(:,1) = randPoint(params.R0); 80 | index=1; 81 | for j=1:options.dim_x:initpoints*options.dim_x 82 | x(j:j+options.dim_x-1,1) = randPoint(params.R0); 83 | for i=1:steps 84 | x(j:j+options.dim_x-1,i+1) = fun(x(j:j+options.dim_x-1,i),u(:,index)) +randPoint(options.W); 85 | index=index+1; 86 | end 87 | end 88 | 89 | 90 | %combine trajectories 91 | index_0 =1; 92 | index_1 =1; 93 | for j=1:options.dim_x:initpoints*options.dim_x 94 | for i=2:steps+1 95 | x_meas_vec_1(:,index_1) = x(j:j+options.dim_x-1,i); 96 | index_1 = index_1 +1; 97 | end 98 | for i=1:steps 99 | x_meas_vec_0(:,index_0) = x(j:j+options.dim_x-1,i); 100 | index_0 = index_0 +1; 101 | end 102 | end 103 | 104 | 105 | 106 | 107 | % X_+ is X_1T 108 | % X_- is X_0T 109 | % U_- is U_full 110 | X_1T = x_meas_vec_1(:,1:totalsamples); 111 | U_full = u(:,1:totalsamples); 112 | X_0T = x_meas_vec_0(:,1:totalsamples); 113 | 114 | %compute monomials of trajectories 115 | X_2 = X_0T .*X_0T; 116 | X1X2 = X_0T(1,:) .* X_0T(2,:); 117 | U_2 = U_full .*U_full; 118 | U1U2 = U_full(1,:) .* U_full(2,:); 119 | XU = X_0T .*U_full; 120 | X1U2X2U1 = X_0T .* U_full([2 1],:); 121 | data=[ones(1,totalsamples);X_0T;X_2;X1X2;U_full;U_2;U1U2;XU;X1U2X2U1]; 122 | 123 | RANK = rank(data) 124 | % set of A B that is consistent with the data 125 | AB = (X_1T + -1* Wmatzono)*pinv(data); 126 | %[ ones ; X_0T ;X_2 ;X1X2;U_full;U_2 ;U1U2;XU ;X1U2X2U1]); 127 | truedyn=[0 ,0.7 0 ,.320 0 , 0 , 1 0 ,0 0 , 0 ,0 0, 0 0; ... 128 | 0 ,0.09 0 , 0 0.4 , 0 , 0 0 ,0 0 , 0 ,0 0, .320 0]; 129 | % check if the true dynamics is within AB 130 | intAB11 = intervalMatrix(AB); 131 | intAB1 = intAB11.int; 132 | intAB1.sup >= truedyn 133 | intAB1.inf <= truedyn 134 | 135 | % model based reachability 136 | sysDisc = nonlinearSysDT('stirredTankReactor',fun,0.015,2,2); 137 | X_data = cell(N+1,1); 138 | X_data{1} = params.R0; 139 | for i = 1:N 140 | 141 | % monomial of intervals of reachable sets and input 142 | X_z1 = interval(X_data{i}); 143 | U_int = interval(params.U); 144 | 145 | cardint =zonotope([interval([1]);X_z1;X_z1.*X_z1;X_z1(1)*X_z1(2);U_int;U_int.*U_int;U_int(1)*U_int(2);X_z1.*U_int;X_z1(1)*U_int(2);X_z1(2)*U_int(1)]); 146 | X_data{i+1} =AB *cardint + options.W; 147 | X_data{i+1,1}=reduce(X_data{i+1,1},'girard',options.zonotopeOrder); 148 | end 149 | % Reachability Analysis --------------------------------------------------- 150 | 151 | tic 152 | R = reach(sysDisc,params,options); 153 | tComp = toc; 154 | disp("Computation time: " + tComp); 155 | 156 | for i=1:length(R.timePoint.set) 157 | R.timePoint.set{i} = R.timePoint.set{i} +options.W ; 158 | end 159 | % Simulation Points -------------------------------------------------------------- 160 | 161 | simOpt.points = 500; 162 | simOpt.fracVert = 0.5; 163 | simOpt.fracInpVert = 0.5; 164 | simOpt.inpChanges = 3; 165 | 166 | simRes = simulateRandom(sysDisc, params, simOpt); 167 | 168 | 169 | % Visualization ----------------------------------------------------------- 170 | 171 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 172 | hold on; box on; 173 | handleX0 = plot(params.R0,[1,2],'k-','LineWidth',2); 174 | 175 | % add noise to the simulation data points 176 | pts =[]; 177 | for i =1:length(simRes.x) 178 | for j = 1:length(simRes.x{i}) 179 | noisept = randPoint(options.W); 180 | pts = [ pts ; simRes.x{i}(j,:) + noisept']; 181 | end 182 | end 183 | handelpts = plot(pts(:,1),pts(:,2),'.k'); 184 | 185 | 186 | % formatting 187 | xlabel('x_1'); 188 | ylabel('x_2'); 189 | % 190 | projectedDims = {[1 2]};%,[3 4],[4 5]}; 191 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 192 | index=1; 193 | numberofplots = N+1;%length(X_model) 194 | for plotRun=1:length(projectedDims) 195 | plotRun 196 | 197 | for iSet=2:numberofplots 198 | handleModel= plot( R.timePoint.set{iSet-1},projectedDims{plotRun},'b'); 199 | end 200 | 201 | 202 | % plot reachable sets starting from index 2, since index 1 = X0 203 | for iSet=2:numberofplots 204 | handleDatazono= plot(X_data{iSet},projectedDims{plotRun},'k'); 205 | end 206 | 207 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 208 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 209 | %axis(axx{plotRun}); 210 | % skip warning for extra legend entries 211 | warOrig = warning; warning('off','all'); 212 | legend([handleX0,handleModel,handelpts,handleDatazono],... 213 | 'Initial Set','Set from model','Simulation points','Set from data','Location','northwest'); 214 | warning(warOrig); 215 | ax = gca; 216 | ax.FontSize = 20; 217 | %set(gcf, 'Position', [50, 50, 800, 400]) 218 | ax = gca; 219 | outerpos = ax.OuterPosition; 220 | ti = ax.TightInset; 221 | left = outerpos(1) + ti(1); 222 | bottom = outerpos(2) + ti(2); 223 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 224 | ax_height = outerpos(4) - ti(2) - ti(4); 225 | ax.Position = [left bottom ax_width ax_height]; 226 | 227 | end 228 | 229 | 230 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /examples-cmz/b_linearDT_measnoise.m: -------------------------------------------------------------------------------- 1 | % t_linear_measnoise - computes the data driven reachable set of discrete 2 | % time systems with modeling and measurement noise 3 | % x(k+1) = Ax(k) + Bu(k) + w(k) 4 | % \tilde(x)(k) = x(k) + v(k) 5 | % 6 | % This example can be found in [1]. 7 | % 8 | % Syntax: 9 | % example_measnoise 10 | % 11 | % Inputs: 12 | % no 13 | % 14 | % Outputs: 15 | % no 16 | % 17 | % References: 18 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer,Karl Henrik Johansson 19 | % "Data-Driven Reachability Analysis from Noisy Data" 20 | % Author: Amr Alanwar 21 | % Written: 17-Jan-2021 22 | % Last update: 21-May-2021 23 | % Last revision:--- 24 | 25 | %------------- BEGIN CODE -------------- 26 | 27 | rand('seed',1); 28 | 29 | clear all 30 | close all 31 | %% system dynamics 32 | dim_x = 5; 33 | A = [-1 -4 0 0 0; 4 -1 0 0 0; 0 0 -3 1 0; 0 0 -1 -3 0; 0 0 0 0 -2]; 34 | B_ss = ones(dim_x,1); 35 | C = [1,0,0,0,0]; 36 | D = 0; 37 | % define continuous time system 38 | sys_c = ss(A,B_ss,C,D); 39 | % convert to discrete system 40 | samplingtime = 0.05; 41 | sys_d = c2d(sys_c,samplingtime); 42 | % Number of trajectories 43 | initpoints =10; 44 | % Number of time steps 45 | steps = 2; 46 | totalsamples = initpoints*steps; 47 | % initial set and input 48 | X0 = zonotope(ones(dim_x,1),0.1*diag(ones(dim_x,1))); 49 | U = zonotope(10,0.25); 50 | 51 | %noise zontope W 52 | W = zonotope(zeros(dim_x,1),0.005*ones(dim_x,1)); 53 | %Construct matrix zonotpe \mathcal{M}_w 54 | for i=1:size(W.generators,2) 55 | vec=W.Z(:,i+1); 56 | GW{i}= [ vec,zeros(dim_x,totalsamples-1)]; 57 | for j=1:totalsamples-1 58 | GW{j+i}= [GW{i+j-1}(:,2:end) GW{i+j-1}(:,1)]; 59 | end 60 | end 61 | Wmatzono= matZonotope(zeros(dim_x,totalsamples),GW); 62 | 63 | %measument noise v 64 | V = zonotope(zeros(dim_x,1),0.002*ones(dim_x,1)); 65 | %take care to change the center of Vmatzono if you change V 66 | %Construct matrix zonotpe \mathcal{M}_v 67 | index=1; 68 | for i=1:size(V.generators,2) 69 | vec=V.Z(:,i+1); 70 | GV{index}= [ vec,zeros(dim_x,totalsamples-1)]; 71 | for j=1:totalsamples-1 72 | GV{j+index}= [GV{index+j-1}(:,2:end) GV{index+j-1}(:,1)]; 73 | end 74 | index = j+index+1; 75 | end 76 | Vmatzono= matZonotope(zeros(dim_x,totalsamples),GV); 77 | 78 | %Construct matrix zonotpe \mathcal{M}_Av 79 | AVmatzono = sys_d.A * Vmatzono; 80 | 81 | 82 | % randomly choose constant inputs for each step / sampling time 83 | for i=1:totalsamples 84 | u(i) = randPoint(U); 85 | end 86 | 87 | 88 | % simulate the discrete system starting from random initial points 89 | x(:,1) = randPoint(X0); 90 | index=1; 91 | for j=1:dim_x:initpoints*dim_x 92 | x(j:j+dim_x-1,1) = randPoint(X0); 93 | x_v(j:j+dim_x-1,1) = x(j:j+dim_x-1,1); 94 | for i=1:steps 95 | utraj(j,i) = u(index); 96 | x(j:j+dim_x-1,i+1) = sys_d.A*x(j:j+dim_x-1,i) + sys_d.B*u(index) + randPoint(W); 97 | x_v(j:j+dim_x-1,i+1) = x(j:j+dim_x-1,i+1) + randPoint(V); 98 | index=index+1; 99 | end 100 | end 101 | 102 | 103 | % concatenate the data trajectories 104 | index_0 =1; 105 | index_1 =1; 106 | for j=1:dim_x:initpoints*dim_x 107 | for i=2:steps+1 108 | x_meas_vec_1_v(:,index_1) = x_v(j:j+dim_x-1,i); 109 | index_1 = index_1 +1; 110 | end 111 | for i=1:steps 112 | u_mean_vec_0(:,index_0) = utraj(j,i); 113 | x_meas_vec_0_v(:,index_0) = x_v(j:j+dim_x-1,i); 114 | x_meas_vec_0(:,index_0) = x(j:j+dim_x-1,i); 115 | index_0 = index_0 +1; 116 | end 117 | end 118 | 119 | % X_+ is X_1T 120 | % X_- is X_0T 121 | % U_- is U_full 122 | U_full = u_mean_vec_0(:,1:totalsamples); %same as u 123 | X_0T = x_meas_vec_0_v(:,1:totalsamples); 124 | X_1T = x_meas_vec_1_v(:,1:totalsamples); 125 | X_0T_pure = x_meas_vec_0(:,1:totalsamples); 126 | 127 | mink= -1*Wmatzono + -1*Vmatzono + AVmatzono; 128 | %compute A_tildeNsigma and B_tildeNsigma 129 | basis=null([X_0T;U_full]); 130 | for i=1:length(mink.generator) 131 | Acon{i}=(mink.generator{i})*basis; 132 | end 133 | Bcon = (X_1T-zeros(dim_x,totalsamples))*basis ; 134 | 135 | %% AB with AV assumption (tildeMsigma) 136 | AB_av = (X_1T + -1*Wmatzono + -1* Vmatzono + AVmatzono)*pinv([X_0T;U_full]); 137 | 138 | 139 | % constrained matrix zonotope AB with AV assumption (tildeNsigma) 140 | AB_cmz = conMatZonotope(AB_av.center,AB_av.generator,Acon,Bcon); 141 | 142 | 143 | % plot simulated trajectory 144 | figure; 145 | subplot(1,2,1); hold on; box on; plot(x(1,:),x(2,:),'b'); xlabel('x_1'); ylabel('x_2'); 146 | subplot(1,2,2); hold on; box on; plot(x(3,:),x(4,:),'b'); xlabel('x_3'); ylabel('x_4'); 147 | close; 148 | 149 | 150 | 151 | %% AB wihtout AV assumption (Algorithm 4 LTIMeasReachability) 152 | X1W_cen = X_1T - Wmatzono.center- Vmatzono.center; 153 | AB = X1W_cen *pinv([X_0T;U_full]); 154 | minTerm = min((X_1T - AB * ([X_0T;U_full]))')'; 155 | maxTerm = max((X_1T - AB * ([X_0T;U_full]))')'; 156 | AV_oneterm = zonotope(interval(minTerm,maxTerm))+ -1*W + -1*V; 157 | %%%%%%%%%%%%%%%%%%%% 158 | %% 159 | %checking if true A B are within the set 160 | AV_minus_matzono = X_1T - AB * ([X_0T;U_full])+ -1*Wmatzono + -1*Vmatzono; 161 | AB_f= (AB * ([X_0T;U_full]) + AV_minus_matzono)*pinv([X_0T_pure;U_full]); 162 | intAB11 = intervalMatrix(AB_f); 163 | intAB1 = intAB11.int; 164 | intAB1.sup >= [sys_d.A,sys_d.B] 165 | intAB1.inf <= [sys_d.A,sys_d.B] 166 | VInt = intervalMatrix(AV_minus_matzono); 167 | leftLimit = VInt.Inf; 168 | rightLimit = VInt.Sup; 169 | AV_minus= zonotope(interval(min(leftLimit')',max(rightLimit')')); 170 | figure;plot(AV_minus,[ 1 2],'r');hold on;plot(AV_oneterm,[ 1 2],'k'); 171 | close; 172 | 173 | %% 174 | 175 | %% compute next step sets from model / data 176 | 177 | % set number of steps in analysis 178 | totalsteps = 3; 179 | %model based reachability 180 | X_model = cell(totalsteps+1,1); 181 | X_model{1} = X0; 182 | 183 | %Algorithm 4 184 | X_data = cell(totalsteps+1,1); 185 | X_data_tilde = cell(totalsteps+1,1); 186 | X_data{1} = X0; 187 | X_data_tilde{1} = X0; 188 | 189 | 190 | 191 | %using matrix zonotope 192 | X_data_av = cell(totalsteps+1,1); 193 | X_data_av{1} = X0; 194 | 195 | %reach using constrained matrix zonotope 196 | X_data_cmz = cell(totalsteps+1,1); 197 | X_data_cmz{1} = conZonotope(X0); 198 | 199 | tic 200 | redOrder = 390; 201 | for i=1:totalsteps 202 | i 203 | % 1) model-based computation 204 | 205 | X_model{i+1,1} = sys_d.A * X_model{i} + sys_d.B * U+W; 206 | X_model{i+1,1}=reduce(X_model{i+1,1},'girard',redOrder); 207 | 208 | % 2) Data Driven approach with Av assumption 209 | X_data_av{i+1,1} = AB_av * (cartProd(X_data_av{i},U)) +W; 210 | X_data_av{i+1,1}=reduce(X_data_av{i+1,1},'girard',redOrder); 211 | 212 | 213 | % 3) Data Driven approach cmz with Av assumption 214 | cart_cmz = cartProd(X_data_cmz{i},conZonotope(U)); 215 | %cart_cmz = cartProd(zonotope(X_data_cmz{i}.Z),U); 216 | X_data_cmz{i+1,1} = AB_cmz*cart_cmz +W; 217 | X_data_cmz{i+1,1}=reduce(X_data_cmz{i+1,1},'girard',redOrder); 218 | 219 | % 4) Data Driven approach without Av assumption (algorithm 4) 220 | if i==1 221 | X_data{i+1,1} = AB * (cartProd(X_data{i},U))+AV_oneterm +W; 222 | X_data_tilde{i+1} = X_data{i+1}+V; 223 | else 224 | X_data{i+1,1} = AB * (cartProd(X_data{i}+ V,U))+AV_oneterm +W; 225 | %or 226 | %X_data_tilde{i+1,1} = AB * (cartProd(X_data_tilde{i},U))+AV_minus +W +V; 227 | %X_data{i+1,1}=X_data_tilde{i+1,1}+-1*V; 228 | end 229 | X_data{i+1,1}=reduce(X_data{i+1,1},'girard',redOrder); 230 | end 231 | exec_time = toc/60 232 | 233 | 234 | 235 | %% visualization 236 | 237 | projectedDims = {[1 2],[3 4],[4 5]}; 238 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 239 | index=1; 240 | numberofplots = totalsteps+1;% 241 | for plotRun=1:length(projectedDims) 242 | plotRun 243 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 244 | 245 | 246 | index=index+1; 247 | % plot initial set 248 | handleX0 = plot(X0,projectedDims{plotRun},'k-','LineWidth',2); 249 | hold on; 250 | 251 | 252 | % plot reachable sets starting from index 2, since index 1 = X0 253 | % plot reachable sets from model 254 | for iSet=2:numberofplots 255 | handleModel= plot(X_model{iSet},projectedDims{plotRun},'b','Filled',true,'FaceColor',[.8 .8 .8],'EdgeColor','b'); 256 | end 257 | 258 | % plot reachable sets from data 259 | for iSet=2:numberofplots 260 | handleData= plot(X_data{iSet},projectedDims{plotRun},'k-+'); 261 | end 262 | 263 | % plot reachable sets from data 264 | for iSet=2:numberofplots 265 | handleData_av= plot(X_data_av{iSet},projectedDims{plotRun},'k'); 266 | end 267 | 268 | % plot reachable sets from data 269 | for iSet=2:numberofplots 270 | handleData_cmz= plot(X_data_cmz{iSet},projectedDims{plotRun},'r','Template',128); 271 | end 272 | % label plot 273 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 274 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 275 | %axis(axx{plotRun}); 276 | % skip warning for extra legend entries 277 | warOrig = warning; warning('off','all'); 278 | legend([handleX0,handleModel,handleData,handleData_av,handleData_cmz],... 279 | 'Initial Set','Set from Model','Set from Data','Set From Data (Av-Zono)','Set From Data (Av-ConZono)','Location','northwest'); 280 | warning(warOrig); 281 | ax = gca; 282 | ax.FontSize = 20; 283 | %set(gcf, 'Position', [50, 50, 800, 400]) 284 | ax = gca; 285 | outerpos = ax.OuterPosition; 286 | ti = ax.TightInset; 287 | left = outerpos(1) + ti(1); 288 | bottom = outerpos(2) + ti(2); 289 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 290 | ax_height = outerpos(4) - ti(2) - ti(4); 291 | ax.Position = [left bottom ax_width ax_height]; 292 | %set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]); 293 | end 294 | 295 | 296 | 297 | 298 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /examples-cmz/b_linearDT_sideInfo.m: -------------------------------------------------------------------------------- 1 | 2 | % example_sideInfo - example of linear reachability analysis with side 3 | % information. This example generates the reachable regoins using matrix 4 | % zonotope, constrained matrix zonotope with exact noise description, and 5 | % side information. 6 | % 7 | % This example can be found in [1]. 8 | % 9 | % Syntax: 10 | % example_sideInfo 11 | % 12 | % Inputs: 13 | % no 14 | % 15 | % Outputs: 16 | % no 17 | % 18 | % References: 19 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer,Karl Henrik Johansson 20 | % "Data-Driven Reachability Analysis from Noisy Data" 21 | % Author: Amr Alanwar 22 | % Written: 17-Jan-2021 23 | % Last update: 21-May-2021 24 | % Last revision:--- 25 | 26 | %------------- BEGIN CODE -------------- 27 | rand('seed',1); 28 | 29 | clear all 30 | close all 31 | clock 32 | %% system dynamics 33 | dim_x = 5; 34 | A = [-1 -4 0 0 0; 4 -1 0 0 0; 0 0 -3 1 0; 0 0 -1 -3 0; 0 0 0 0 -2]; 35 | B_ss = ones(5,1); 36 | C = [1,0,0,0,0]; 37 | D = 0; 38 | % define continuous time system 39 | sys_c = ss(A,B_ss,C,D); 40 | % convert to discrete system 41 | samplingtime = 0.05; 42 | sys_d = c2d(sys_c,samplingtime); 43 | 44 | % number of trajectories 45 | initpoints =10; 46 | % number of step per trajectory 47 | steps = 3; 48 | 49 | % total number of data points 50 | totalsamples = initpoints*steps; 51 | %% initial set and input 52 | X0 = zonotope(ones(dim_x,1),0.1*diag(ones(dim_x,1))); 53 | U = zonotope(10,0.25); 54 | 55 | %noise zontope W 56 | W = zonotope(zeros(dim_x,1),0.005*ones(dim_x,1)); 57 | GW={}; 58 | index=1; 59 | for i=1:size(W.generators,2) 60 | vec=W.Z(:,i+1); 61 | GW{index}= [ vec,zeros(dim_x,totalsamples-1)]; 62 | for j=1:totalsamples-1 63 | GW{j+index}= [GW{index+j-1}(:,2:end) GW{index+j-1}(:,1)]; 64 | end 65 | index = j+index+1; 66 | end 67 | 68 | % concatinate W to get matrix zonotope Wmatzono 69 | Wmatzono= matZonotope(zeros(dim_x,totalsamples),GW); 70 | 71 | 72 | 73 | 74 | % randomly choose constant inputs for each step / sampling time 75 | for i=1:totalsamples 76 | u(i) = randPoint(U); 77 | end 78 | 79 | 80 | % simulate the discrete system starting from rand point inside X0 81 | index=1; 82 | for j=1:dim_x:initpoints*dim_x 83 | x(j:j+dim_x-1,1) = randPoint(X0); 84 | for i=1:steps 85 | utraj(j,i) = u(index); 86 | x(j:j+dim_x-1,i+1) = sys_d.A*x(j:j+dim_x-1,i) + sys_d.B*u(index) + randPoint(W); 87 | index=index+1; 88 | end 89 | end 90 | 91 | 92 | 93 | index_0 =1; 94 | index_1 =1; 95 | for j=1:dim_x:initpoints*dim_x 96 | for i=2:steps+1 97 | x_meas_vec_1(:,index_1) = x(j:j+dim_x-1,i); 98 | index_1 = index_1 +1; 99 | end 100 | for i=1:steps 101 | u_mean_vec_0(:,index_0) = utraj(j,i); 102 | x_meas_vec_0(:,index_0) = x(j:j+dim_x-1,i); 103 | index_0 = index_0 +1; 104 | end 105 | end 106 | 107 | %U_- 108 | U_full = u_mean_vec_0(:,1:totalsamples); %same as u 109 | %X_- 110 | X_0T = x_meas_vec_0(:,1:totalsamples); 111 | %X_+ 112 | X_1T = x_meas_vec_1(:,1:totalsamples); 113 | 114 | 115 | %compute A_Nw and B_Nw 116 | basis=null([X_0T;U_full]); 117 | for i=1:length(GW) 118 | Acon{i}=GW{i}*basis; 119 | end 120 | Bcon = (X_1T-zeros(dim_x,totalsamples))*basis ; 121 | %N_w 122 | Wconmat = conMatZonotope(zeros(dim_x,totalsamples),GW,Acon,Bcon); 123 | 124 | % plot simulated trajectory 125 | figure; 126 | subplot(1,2,1); hold on; box on; plot(x(1,:),x(2,:),'b'); xlabel('x_1'); ylabel('x_2'); 127 | subplot(1,2,2); hold on; box on; plot(x(3,:),x(4,:),'b'); xlabel('x_3'); ylabel('x_4'); 128 | close; 129 | 130 | 131 | X1W_cen = X_1T - Wconmat.center; 132 | X1W_cmz = conMatZonotope(X1W_cen,Wconmat.generator,Wconmat.A,Wconmat.B); 133 | X1W = matZonotope(X1W_cen,Wconmat.generator); 134 | 135 | %compute N_sigma 136 | AB_cmz = X1W_cmz * pinv([X_0T;U_full]); 137 | %compute M_sigma 138 | AB = X1W *pinv([X_0T;U_full]); 139 | 140 | %double check that the true system dyn are inside AB 141 | intAB11 = intervalMatrix(AB); 142 | intAB1 = intAB11.int; 143 | intAB1.sup >= [sys_d.A,sys_d.B] 144 | intAB1.inf <= [sys_d.A,sys_d.B] 145 | 146 | %specify side informaiton about the A B 147 | Y = zeros(5,6); 148 | Q = eye(5); 149 | rfac = 0.005; 150 | R = [ 1 1 rfac rfac rfac 1;... 151 | 1 1 rfac rfac rfac 1;... 152 | rfac rfac 1 1 rfac 1;... 153 | rfac rfac 1 1 rfac 1;... 154 | rfac rfac rfac rfac 1 1]; 155 | 156 | 157 | %list of R ( 158 | index=1; 159 | for i=1:5 160 | for j=1:6 161 | RList{index} =zeros(5,6); 162 | RList{index}(i,j) = R(i,j); 163 | index = index+1; 164 | end 165 | end 166 | 167 | 168 | % compute N_s = 169 | for i =1:length(AB_cmz.generator) 170 | Aside{i} = [Q*AB_cmz.generator{i}]; 171 | [row_side,col_side]=size(Aside{i}); 172 | [row_A, col_A]= size(AB_cmz.A{i}); 173 | AB_cmz_new_A{i} = [ AB_cmz.A{i};Aside{i},zeros(row_side,col_A-col_side)]; 174 | end 175 | %add one more beta for A and generators 176 | AB_cmz_gen_new = AB_cmz.generator; 177 | for i=1:length(RList) 178 | AB_cmz_new_A{length(AB_cmz.generator)+i} = [zeros(row_A,col_A);-RList{i},zeros(row_side,col_A-col_side) ]; 179 | AB_cmz_gen_new{length(AB_cmz.generator)+i} = zeros(size(AB_cmz.generator{1})); 180 | end 181 | 182 | Bside =Y- Q * AB_cmz.center ; 183 | AB_cmz_new_B = [ AB_cmz.B;Bside,zeros(row_side,col_A-col_side)] ; 184 | 185 | %N_s 186 | AB_cmz_side = conMatZonotope(AB_cmz.center,AB_cmz_gen_new,AB_cmz_new_A,AB_cmz_new_B); 187 | 188 | 189 | 190 | 191 | %% compute next step sets from model / data 192 | 193 | % set number of steps in analysis 194 | totalsteps = 3; 195 | % \mathcal{R} 196 | X_model = cell(totalsteps+1,1); 197 | % \hat{\mathcal{R}} 198 | X_data = cell(totalsteps+1,1); 199 | % \bar{\mathcal{R}} 200 | X_data_cmz = cell(totalsteps+1,1); 201 | % \bar{\mathcal{R}}^s 202 | X_data_cmz_side = cell(totalsteps+1,1); 203 | 204 | % init sets for loop 205 | X_model{1} = X0; 206 | X_data{1} = X0; 207 | X_data_cmz{1} = conZonotope(X0); 208 | X_data_cmz_side{1} = conZonotope(X0); 209 | 210 | delFlag = 0; 211 | redFact = 200; 212 | execTimeModel = 0; 213 | execTimeData = 0; 214 | execTimeCmz = 0; 215 | execTimeSide = 0; 216 | for i=1:totalsteps 217 | i 218 | % 1) model-based computation 219 | tic() 220 | X_model{i+1,1} = sys_d.A * X_model{i} + sys_d.B * U+W; 221 | execTimeModel=execTimeModel + toc()/60; 222 | X_model{i+1,1}=reduce(X_model{i+1,1},'girard',redFact); 223 | 224 | %2) data driven matrix zonotope 225 | tic() 226 | X_data{i+1,1} = AB*cartProd(X_data{i},U) +W; 227 | execTimeData=execTimeData + toc()/60; 228 | X_data{i+1,1} = reduce(X_data{i+1,1},'girard',redFact); 229 | 230 | 231 | % 3) Data Driven approach using exact noise description 232 | tic() 233 | cart_cmz = cartProd(X_data_cmz{i},conZonotope(U)); 234 | X_data_cmz{i+1,1} = AB_cmz*cart_cmz +W; 235 | execTimeCmz=execTimeCmz + toc()/60; 236 | X_data_cmz{i+1,1}=reduce(X_data_cmz{i+1,1},'girard',redFact); %390 237 | 238 | % 4) Data Driven approach using side information 239 | tic() 240 | X_data_cmz_side{i+1,1} = AB_cmz_side*cartProd(X_data_cmz_side{i},conZonotope(U)) +W; 241 | execTimeSide=execTimeSide + toc()/60; 242 | X_data_cmz_side{i+1,1}=reduce(X_data_cmz_side{i+1,1},'girard',redFact); 243 | 244 | end 245 | execTimeModel=execTimeModel/totalsteps 246 | execTimeData=execTimeData/totalsteps 247 | execTimeCmz=execTimeCmz/totalsteps 248 | execTimeSide=execTimeSide/totalsteps 249 | 250 | %% visualization 251 | 252 | projectedDims = {[1 2],[3 4],[4 5]}; 253 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 254 | index=1; 255 | numberofplots = totalsteps+1;%length(X_model) 256 | for plotRun=1:length(projectedDims) 257 | plotRun 258 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 259 | 260 | % set axis 261 | 262 | index=index+1; 263 | % plot initial set 264 | handleX0 = plot(X0,projectedDims{plotRun},'k-','LineWidth',2); 265 | hold on; 266 | 267 | 268 | % plot reachable sets starting from index 2, since index 1 = X0 269 | 270 | % plot reachable sets from model 271 | for iSet=2:numberofplots 272 | handleModel= plot(X_model{iSet},projectedDims{plotRun},'b','Filled',true,'FaceColor',[.8 .8 .8],'EdgeColor','b'); 273 | end 274 | 275 | % plot reachable sets from data 276 | for iSet=2:numberofplots 277 | handleDatacon = plot(X_data_cmz{iSet},projectedDims{plotRun},'r','Template',128);%,'Splits',0); 278 | end 279 | 280 | % plot reachable sets from data 281 | for iSet=2:numberofplots 282 | handleDataconside = plot(X_data_cmz_side{iSet},projectedDims{plotRun},'r*-','Template',128);%,'Splits',0); 283 | end 284 | % plot reachable sets from data 285 | for iSet=2:numberofplots 286 | handleDatazono = plot(X_data{iSet},projectedDims{plotRun},'k'); 287 | end 288 | % label plot 289 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 290 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 291 | %axis(axx{plotRun}); 292 | % skip warning for extra legend entries 293 | warOrig = warning; warning('off','all'); 294 | legend([handleX0,handleModel,handleDatazono,handleDatacon,handleDataconside],... 295 | 'Initial set $\mathcal{X}_0$','Set from model $\mathcal{R}_k$','Set from data $\hat{\mathcal{R}}_k$','Set from data $\bar{\mathcal{R}}_k$','Set from data $\bar{\mathcal{R}}_k^{s}$','Interpreter','latex'); 296 | warning(warOrig); 297 | ax = gca; 298 | ax.FontSize = 20; 299 | %set(gcf, 'Position', [50, 50, 800, 400]) 300 | ax = gca; 301 | outerpos = ax.OuterPosition; 302 | ti = ax.TightInset; 303 | left = outerpos(1) + ti(1); 304 | bottom = outerpos(2) + ti(2); 305 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 306 | ax_height = outerpos(4) - ti(2) - ti(4); 307 | ax.Position = [left bottom ax_width ax_height]; 308 | %set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]); 309 | end 310 | 311 | 312 | 313 | 314 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /examples-cmz/b_polyDT_sideInfo.m: -------------------------------------------------------------------------------- 1 | % example_poly_sideInfo - example of reachability analysis for polynomial systems with side 2 | % information. This example generates the reachable regoins using matrix 3 | % zonotope, constrained matrix zonotope with exact noise description, and 4 | % side information. 5 | % 6 | % This example can be found in [1]. 7 | % 8 | % Syntax: 9 | % example_sideInfo 10 | % 11 | % Inputs: 12 | % no 13 | % 14 | % Outputs: 15 | % no 16 | % 17 | % References: 18 | % [1] Amr Alanwar, Anne Koch, Frank Allgöwer,Karl Henrik Johansson 19 | % "Data-Driven Reachability Analysis from Noisy Data" 20 | % Author: Amr Alanwar 21 | % Written: 17-Jan-2021 22 | % Last update: 21-May-2021 23 | % Last revision:--- 24 | 25 | %------------- BEGIN CODE -------------- 26 | 27 | clear all 28 | close all 29 | rand('seed',50); 30 | %time steps 31 | N=3; 32 | dt = 0.015; 33 | %final time for model based reachability 34 | params.tFinal = dt*N; 35 | 36 | %input set 37 | params.U = zonotope([[0.2;0.3],diag([0.01,0.02])]); 38 | %initial set 39 | params.R0 = zonotope([[1;2],diag([0.05;0.3])]); 40 | 41 | 42 | % dimension of x 43 | options.dim_x=2; 44 | 45 | %Number of trajectories 46 | initpoints=25; 47 | %Number of time steps 48 | steps=7; 49 | 50 | %Totoal number of samples 51 | totalsamples = steps*initpoints; 52 | 53 | %noise zonotope 54 | wfac = 0.7e-4; 55 | options.W = zonotope(zeros(options.dim_x,1),wfac*ones(options.dim_x,1)); % disturbance 56 | 57 | %noise matrix zonotope 58 | for i=1:size(options.W.generators,2) 59 | vec=options.W.Z(:,i+1); 60 | for j=0:totalsamples-1 61 | GW{j+i}= [ zeros(options.dim_x,j),vec,zeros(options.dim_x,totalsamples-j-1)]; 62 | end 63 | end 64 | Wmatzono= matZonotope(zeros(options.dim_x,totalsamples),GW); 65 | 66 | % Reachability Settings 67 | options.zonotopeOrder = 200; 68 | options.tensorOrder = 2; 69 | options.errorOrder = 5; 70 | 71 | 72 | % True system dynamics 73 | fun = @(x,u) polyFun(x,u,dt); 74 | 75 | %input random sample points 76 | for i=1:totalsamples 77 | u(:,i) = randPoint(params.U); 78 | end 79 | 80 | %get state trajectories 81 | x(:,1) = randPoint(params.R0); 82 | index=1; 83 | for j=1:options.dim_x:initpoints*options.dim_x 84 | x(j:j+options.dim_x-1,1) = randPoint(params.R0); 85 | for i=1:steps 86 | x(j:j+options.dim_x-1,i+1) = fun(x(j:j+options.dim_x-1,i),u(:,index)) +randPoint(options.W); 87 | index=index+1; 88 | end 89 | end 90 | 91 | 92 | %combine trajectories 93 | index_0 =1; 94 | index_1 =1; 95 | for j=1:options.dim_x:initpoints*options.dim_x 96 | for i=2:steps+1 97 | x_meas_vec_1(:,index_1) = x(j:j+options.dim_x-1,i); 98 | index_1 = index_1 +1; 99 | end 100 | for i=1:steps 101 | x_meas_vec_0(:,index_0) = x(j:j+options.dim_x-1,i); 102 | index_0 = index_0 +1; 103 | end 104 | end 105 | 106 | 107 | 108 | 109 | % X_+ is X_1T 110 | % X_- is X_0T 111 | % U_- is U_full 112 | X_1T = x_meas_vec_1(:,1:totalsamples); 113 | U_full = u(:,1:totalsamples); 114 | X_0T = x_meas_vec_0(:,1:totalsamples); 115 | 116 | %compute monomials of trajectories 117 | X_2 = X_0T .*X_0T; 118 | X1X2 = X_0T(1,:) .* X_0T(2,:); 119 | U_2 = U_full .*U_full; 120 | U1U2 = U_full(1,:) .* U_full(2,:); 121 | XU = X_0T .*U_full; 122 | X1U2X2U1 = X_0T .* U_full([2 1],:); 123 | data=[ones(1,totalsamples);X_0T;X_2;X1X2;U_full;U_2;U1U2;XU;X1U2X2U1]; 124 | 125 | 126 | %%%%%%%%%%%%%%% 127 | dim_x =2; 128 | nn=null(data); 129 | basis = nn;%*nn';%*pinv(nn);%null([X_0T;U_full])*pinv(null([X_0T;U_full])); 130 | for i=1:length(GW) 131 | Acon{i}=GW{i}*basis; 132 | end 133 | Bcon = (X_1T-zeros(dim_x,totalsamples))*basis; 134 | 135 | Wconmat = conMatZonotope(zeros(dim_x,totalsamples),GW,Acon,Bcon); 136 | %% 137 | RANK = rank(data) 138 | % set of A B that is consistent with the data 139 | AB = (X_1T + -1* Wmatzono)*pinv(data); 140 | %[ ones ; X_0T ;X_2 ;X1X2;U_full;U_2 ;U1U2;XU ;X1U2X2U1]); 141 | truedyn=[ 0,0.7 0 ,0.32 0 , 0 , 1 0 ,0 0 , 0 ,0 0, 0 0; ... 142 | 0,0.09 0 ,0 0.4 , 0 , 0 0 ,0 0 , 0 ,0 0 , .320 0]; 143 | % check if the true dynamics is within AB 144 | intAB11 = intervalMatrix(AB); 145 | intAB1 = intAB11.int; 146 | intAB1.sup >= truedyn 147 | intAB1.inf <= truedyn 148 | 149 | % constrain matrix zonotpe that is consitent with data and exact noise 150 | % description 151 | X1W_cen = X_1T - Wconmat.center; 152 | X1W_cmz = conMatZonotope(X1W_cen,Wconmat.generator,Wconmat.A,Wconmat.B); 153 | AB_cmz = X1W_cmz * pinv(data); 154 | 155 | %side information 156 | [r_c c_c]= size(truedyn); 157 | Q = eye(r_c); 158 | Y = zeros(r_c,c_c); 159 | rfac = 0.1; 160 | %[ one ; X_0T ;X_2 ;X1X2 ;U_full ;U_2 ;U1U2 ;XU ;X1U2X2U1]); 161 | Rmat =[ rfac,1 rfac ,1 rfac , rfac , 1.2 rfac ,rfac rfac , rfac ,rfac rfac , rfac rfac; ... 162 | rfac,1 rfac,rfac 1 , rfac , rfac rfac ,rfac rfac , rfac ,rfac rfac ,1 rfac]; 163 | index=1; 164 | for i=1:r_c 165 | for j=1:c_c 166 | % if R(i,j) ~=rfac 167 | RList{index} =zeros(r_c,c_c); 168 | RList{index}(i,j) = Rmat(i,j); 169 | index = index+1; 170 | % end 171 | end 172 | end 173 | 174 | 175 | %add constraint from side information 176 | for i =1:length(AB_cmz.generator) 177 | Aside{i} = [Q*AB_cmz.generator{i}]; 178 | [row_side,col_side]=size(Aside{i}); 179 | [row_A, col_A]= size(AB_cmz.A{i}); 180 | AB_cmz_new_A{i} = [ AB_cmz.A{i};Aside{i},zeros(row_side,col_A-col_side)]; 181 | end 182 | AB_cmz_gen_new = AB_cmz.generator; 183 | for i=1:length(RList) 184 | AB_cmz_new_A{length(AB_cmz.generator)+i} = [zeros(row_A,col_A);-RList{i},zeros(row_side,col_A-col_side) ]; 185 | AB_cmz_gen_new{length(AB_cmz.generator)+i} = zeros(size(AB_cmz.generator{1})); 186 | end 187 | 188 | Bside =Y- Q * AB_cmz.center ; 189 | AB_cmz_new_B = [ AB_cmz.B;Bside,zeros(row_side,col_A-col_side)] ; 190 | 191 | % constrain matrix zonotpe that is consitent with data, exact noise 192 | % description and side information 193 | AB_cmz_side = conMatZonotope(AB_cmz.center,AB_cmz_gen_new,AB_cmz_new_A,AB_cmz_new_B); 194 | %% 195 | % Model based reachability 196 | sysDisc = nonlinearSysDT('stirredTankReactor',fun,0.015,2,2); 197 | %reachable set using matrix zonotope 198 | X_data = cell(N+1,1); 199 | %reachable set using constrained matrix zonotope and exact noise 200 | %description 201 | X_data_cmz = cell(N+1,1); 202 | %reachable set using constrained matrix zonotope, exact noise 203 | %description and side information 204 | X_data_cmz_side = cell(N+1,1); 205 | X_data{1} = params.R0; 206 | X_data_cmz{1} = conZonotope(params.R0); 207 | X_data_cmz_side{1} = conZonotope(params.R0); 208 | execTimeModel = 0; 209 | execTimeData = 0; 210 | execTimeCmz = 0; 211 | execTimeSide = 0; 212 | for i = 1:N 213 | i 214 | %compute monomial of each reachable set 215 | X_z1 = interval(X_data{i}); 216 | U_int = interval(params.U); 217 | tic() 218 | card =zonotope([interval([1]);X_z1;X_z1.*X_z1;X_z1(1)*X_z1(2);U_int;U_int.*U_int;U_int(1)*U_int(2);X_z1.*U_int;X_z1(1)*U_int(2);X_z1(2)*U_int(1)]); 219 | X_data{i+1} = AB *card +options.W ; 220 | execTimeData=execTimeData + toc()/60; 221 | X_data{i+1,1}=reduce(X_data{i+1,1},'girard',options.zonotopeOrder); 222 | 223 | X_z1 = interval(X_data_cmz{i}); 224 | tic() 225 | card_cmz =zonotope([interval([1]);X_z1;X_z1.*X_z1;X_z1(1)*X_z1(2);U_int;U_int.*U_int;U_int(1)*U_int(2);X_z1.*U_int;X_z1(1)*U_int(2);X_z1(2)*U_int(1)]); 226 | X_data_cmz{i+1} = AB_cmz *card_cmz+options.W ; 227 | execTimeCmz=execTimeCmz + toc()/60; 228 | X_data_cmz{i+1,1}=reduce(X_data_cmz{i+1,1},'girard',options.zonotopeOrder); 229 | 230 | X_z1 = interval(X_data_cmz_side{i}); 231 | tic() 232 | card_cmz_side=zonotope([interval([1]);X_z1;X_z1.*X_z1;X_z1(1)*X_z1(2);U_int;U_int.*U_int;U_int(1)*U_int(2);X_z1.*U_int;X_z1(1)*U_int(2);X_z1(2)*U_int(1)]); 233 | X_data_cmz_side{i+1} = AB_cmz_side *card_cmz_side+options.W ; 234 | execTimeSide=execTimeSide + toc()/60; 235 | X_data_cmz_side{i+1}=reduce(X_data_cmz_side{i+1},'girard',options.zonotopeOrder); 236 | end 237 | execTimeData=execTimeData/N 238 | execTimeCmz=execTimeCmz/N 239 | execTimeSide=execTimeSide/N 240 | % Reachability Analysis --------------------------------------------------- 241 | 242 | tic 243 | R = reach(sysDisc,params,options); 244 | tComp = toc/60; 245 | disp("Computation time: " + tComp); 246 | 247 | for i=1:length(R.timePoint.set) 248 | R.timePoint.set{i} = R.timePoint.set{i} +options.W ; 249 | end 250 | 251 | 252 | % Simulation -------------------------------------------------------------- 253 | 254 | simOpt.points = 500; 255 | simOpt.fracVert = 0.5; 256 | simOpt.fracInpVert = 0.5; 257 | simOpt.inpChanges = 3; 258 | 259 | simRes = simulateRandom(sysDisc, params, simOpt); 260 | 261 | 262 | % Visualization ----------------------------------------------------------- 263 | 264 | 265 | 266 | % plot initial set 267 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 268 | hold on; box on; 269 | handleX0 = plot(params.R0,[1,2],'k-','LineWidth',2); 270 | 271 | 272 | pts =[]; 273 | for i =1:length(simRes.x) 274 | for j = 1:length(simRes.x{i}) 275 | noisept = randPoint(options.W); 276 | pts = [ pts ; simRes.x{i}(j,:) + noisept']; 277 | end 278 | end 279 | handelpts = plot(pts(:,1),pts(:,2),'.k'); 280 | % formatting 281 | xlabel('x_1'); 282 | ylabel('x_2'); 283 | % 284 | projectedDims = {[1 2]};%,[3 4],[4 5]}; 285 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 286 | index=1; 287 | numberofplots = N+1;%length(X_model) 288 | for plotRun=1:length(projectedDims) 289 | 290 | plotRun 291 | 292 | % plot reachable sets starting from index 2, since index 1 = X0 293 | for iSet=2:numberofplots 294 | handleModel= plot( R.timePoint.set{iSet-1},projectedDims{plotRun},'b'); 295 | end 296 | 297 | for iSet=2:numberofplots 298 | handleDatazono = plot(X_data{iSet},projectedDims{plotRun},'k'); 299 | end 300 | for iSet=2:numberofplots 301 | handleDataconside = plot(X_data_cmz_side{iSet},projectedDims{plotRun},'r*-','Template',200); 302 | end 303 | for iSet=2:numberofplots 304 | handleDatacon = plot(X_data_cmz{iSet},projectedDims{plotRun},'r','Template',200); 305 | end 306 | 307 | 308 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 309 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 310 | %axis(axx{plotRun}); 311 | % skip warning for extra legend entries 312 | warOrig = warning; warning('off','all'); 313 | legend([handleX0,handleModel,handelpts,handleDatazono,handleDatacon,handleDataconside],... 314 | 'Initial Set','Set from model','Simulation points','Set from data (Zono)','Set from data (ConZono)','Set from data (Side-info)','Location','northwest'); 315 | warning(warOrig); 316 | ax = gca; 317 | ax.FontSize = 20; 318 | %set(gcf, 'Position', [50, 50, 800, 400]) 319 | ax = gca; 320 | outerpos = ax.OuterPosition; 321 | ti = ax.TightInset; 322 | left = outerpos(1) + ti(1); 323 | bottom = outerpos(2) + ti(2); 324 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 325 | ax_height = outerpos(4) - ti(2) - ti(4); 326 | ax.Position = [left bottom ax_width ax_height]; 327 | end 328 | 329 | % example completed 330 | completed = 1; 331 | 332 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /plotting/p_plot_linearDT_measnoise.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | 4 | load('AMRTest\workspace\good\run_3appIn10S2_0_005w_0_002v_red390.mat') 5 | 6 | projectedDims = {[1 2],[3 4],[4 5]}; 7 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 8 | index=1; 9 | numberofplots = totalsteps+1;% 10 | for plotRun=1:length(projectedDims) 11 | plotRun 12 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 13 | 14 | 15 | index=index+1; 16 | % plot initial set 17 | handleX0 = plot(X0,projectedDims{plotRun},'k-','LineWidth',2); 18 | hold on; 19 | 20 | 21 | % plot reachable sets starting from index 2, since index 1 = X0 22 | % plot reachable sets from model 23 | for iSet=2:numberofplots 24 | handleModel= plot(X_model{iSet},projectedDims{plotRun},'b','Filled',true,'FaceColor',[.8 .8 .8],'EdgeColor','b'); 25 | end 26 | 27 | % plot reachable sets from data 28 | for iSet=2:numberofplots 29 | handleData= plot(X_data{iSet},projectedDims{plotRun},'k-+'); 30 | end 31 | 32 | % plot reachable sets from data 33 | for iSet=2:numberofplots 34 | handleData_av= plot(X_data_av{iSet},projectedDims{plotRun},'k'); 35 | end 36 | 37 | % plot reachable sets from data 38 | for iSet=2:numberofplots 39 | handleData_cmz= plot(X_data_cmz{iSet},projectedDims{plotRun},'r','Template',128); 40 | end 41 | % label plot 42 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 43 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 44 | %axis(axx{plotRun}); 45 | % skip warning for extra legend entries 46 | warOrig = warning; warning('off','all'); 47 | % legend([handleX0,handleModel,handleData,handleData_av,handleData_cmz],... 48 | % 'Initial Set','Set from Model','Set from Data (practical)','Set From Data (Zono-Asm. 2)','Set From Data (ConZono-Asm. 2)','Location','northwest'); 49 | legend([handleX0,handleModel,handleData,handleData_av,handleData_cmz],... 50 | 'Initial set $\mathcal{X}_0$','Set from model $\mathcal{R}_k$','Set from data $\tilde{\mathcal{R}}_k^{m}$','Set from data $\hat{\mathcal{R}}_k^{m}$','Set from data $\bar{\mathcal{R}}_k^{m}$','Interpreter','latex'); 51 | 52 | warning(warOrig); 53 | ax = gca; 54 | ax.FontSize = 22; 55 | %set(gcf, 'Position', [50, 50, 800, 400]) 56 | ax = gca; 57 | outerpos = ax.OuterPosition; 58 | ti = ax.TightInset; 59 | left = outerpos(1) + ti(1); 60 | bottom = outerpos(2) + ti(2); 61 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 62 | ax_height = outerpos(4) - ti(2) - ti(4); 63 | ax.Position = [left bottom ax_width ax_height]; 64 | %set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]); 65 | end 66 | 67 | -------------------------------------------------------------------------------- /plotting/p_plot_linearDT_sideInfo.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | 4 | load('workspace\paper\run_side001In10S3_0_005w_red200.mat') 5 | projectedDims = {[1 2],[3 4],[4 5]}; 6 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 7 | index=1; 8 | numberofplots = totalsteps+1;%length(X_model) 9 | for plotRun=1:length(projectedDims) 10 | plotRun 11 | figure('Renderer', 'painters', 'Position', [10 10 700 900]) 12 | 13 | % set axis 14 | 15 | index=index+1; 16 | % plot initial set 17 | handleX0 = plot(X0,projectedDims{plotRun},'k-','LineWidth',2); 18 | hold on; 19 | 20 | 21 | % plot reachable sets starting from index 2, since index 1 = X0 22 | 23 | % plot reachable sets from model 24 | for iSet=2:numberofplots 25 | handleModel= plot(X_model{iSet},projectedDims{plotRun},'b','Filled',true,'FaceColor',[.8 .8 .8],'EdgeColor','b'); 26 | end 27 | 28 | % plot reachable sets from data 29 | for iSet=2:numberofplots 30 | handleDatacon = plot(X_data_cmz{iSet},projectedDims{plotRun},'r','Template',128);%,'Splits',0); 31 | end 32 | 33 | % plot reachable sets from data 34 | for iSet=2:numberofplots 35 | handleDataconside = plot(X_data_cmz_side{iSet},projectedDims{plotRun},'r*-','Template',128);%,'Splits',0); 36 | end 37 | % plot reachable sets from data 38 | for iSet=2:numberofplots 39 | handleDatazono = plot(X_data{iSet},projectedDims{plotRun},'k'); 40 | end 41 | % label plot 42 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 43 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 44 | %axis(axx{plotRun}); 45 | % skip warning for extra legend entries 46 | warOrig = warning; warning('off','all'); 47 | % legend([handleX0,handleModel,handleDatazono,handleDatacon,handleDataconside],... 48 | % 'Initial Set','Set from model','Set from data (Zono)','Set from data (ConZono)','Set from data (Side-info)','Location','northwest','Interpreter','latex'); 49 | legend([handleX0,handleModel,handleDatazono,handleDatacon,handleDataconside],... 50 | 'Initial set $\mathcal{X}_0$','Set from model $\mathcal{R}_k$','Set from data $\hat{\mathcal{R}}_k$','Set from data $\bar{\mathcal{R}}_k$','Set from data $\bar{\mathcal{R}}_k^{s}$','Interpreter','latex'); 51 | 52 | warning(warOrig); 53 | ax = gca; 54 | ax.FontSize = 22; 55 | %set(gcf, 'Position', [50, 50, 800, 400]) 56 | ax = gca; 57 | outerpos = ax.OuterPosition; 58 | ti = ax.TightInset; 59 | left = outerpos(1) + ti(1); 60 | bottom = outerpos(2) + ti(2); 61 | ax_width = outerpos(3) - ti(1) - ti(3)-0.03; 62 | ax_height = outerpos(4) - ti(2) - ti(4); 63 | ax.Position = [left bottom ax_width ax_height]; 64 | %set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]); 65 | end 66 | -------------------------------------------------------------------------------- /plotting/p_plot_polyDT_sideInfo.m: -------------------------------------------------------------------------------- 1 | clear all 2 | %close all 3 | 4 | load('workspace\paper\run_poly2.mat') 5 | % plot initial set 6 | figure('Renderer', 'painters', 'Position', [10 10 800 900]) 7 | hold on; box on; 8 | handleX0 = plot(params.R0,[1,2],'k-','LineWidth',2); 9 | 10 | 11 | pts =[]; 12 | for i =1:length(simRes.x) 13 | for j = 1:length(simRes.x{i}) 14 | noisept = randPoint(options.W); 15 | pts = [ pts ; simRes.x{i}(j,:) + noisept']; 16 | end 17 | end 18 | handelpts = plot(pts(:,1),pts(:,2),'.k'); 19 | % formatting 20 | xlabel('x_1'); 21 | ylabel('x_2'); 22 | % 23 | projectedDims = {[1 2]};%,[3 4],[4 5]}; 24 | axx{1} = [0.75,1.5,0.5,4]; axx{2} = [0.75,3,0.8,2.2];axx{3} = [0.75,2.3,0.75,2.8]; 25 | index=1; 26 | numberofplots = N+1;%length(X_model) 27 | for plotRun=1:length(projectedDims) 28 | 29 | plotRun 30 | 31 | % plot reachable sets starting from index 2, since index 1 = X0 32 | for iSet=2:numberofplots 33 | handleModel= plot( R.timePoint.set{iSet-1},projectedDims{plotRun},'b'); 34 | end 35 | 36 | for iSet=2:numberofplots 37 | handleDatazono = plot(X_data{iSet},projectedDims{plotRun},'k'); 38 | end 39 | for iSet=2:numberofplots 40 | handleDataconside = plot(X_data_cmz_side{iSet},projectedDims{plotRun},'r*-','Template',200); 41 | end 42 | for iSet=2:numberofplots 43 | handleDatacon = plot(X_data_cmz{iSet},projectedDims{plotRun},'r','Template',200); 44 | end 45 | 46 | 47 | xlabel(['x_{',num2str(projectedDims{plotRun}(1)),'}']); 48 | ylabel(['x_{',num2str(projectedDims{plotRun}(2)),'}']); 49 | %axis(axx{plotRun}); 50 | % skip warning for extra legend entries 51 | warOrig = warning; warning('off','all'); 52 | legend([handleX0,handleModel,handelpts,handleDatazono,handleDatacon,handleDataconside],... 53 | 'Initial Set $\mathcal{X}_0$','Set from model','Simulation points','Set from data $\hat{\mathcal{R}}_k^p$','Set from data $\bar{\mathcal{R}}_k^p$','Set from data $\bar{\mathcal{R}}_k^{s,p}$','Location','northwest','Interpreter','latex'); 54 | 55 | 56 | warning(warOrig); 57 | ax = gca; 58 | ax.FontSize = 20; 59 | %set(gcf, 'Position', [50, 50, 800, 400]) 60 | ax = gca; 61 | outerpos = ax.OuterPosition; 62 | ti = ax.TightInset; 63 | left = outerpos(1) + ti(1); 64 | bottom = outerpos(2) + ti(2); 65 | ax_width = outerpos(3) - ti(1) - ti(3)-0.01; 66 | ax_height = outerpos(4) - ti(2) - ti(4); 67 | ax.Position = [left bottom ax_width ax_height]; 68 | end 69 | -------------------------------------------------------------------------------- /utilities/compLipConst.m: -------------------------------------------------------------------------------- 1 | function [gamma,L]= compLipConst(fun,U,R0,steps,initpoints,dim_x) 2 | %compute Lipschitz constant 3 | 4 | totalsamples = initpoints*steps; 5 | %input random sample points 6 | for i=1:totalsamples 7 | u(:,i) = randPointExtreme(U); 8 | end 9 | 10 | %get state trajectories 11 | index=1; 12 | for j=1:dim_x:initpoints*dim_x 13 | x_free(j:j+dim_x-1,1) = randPoint(R0); 14 | for i=1:steps 15 | x_free(j:j+dim_x-1,i+1) = fun(x_free(j:j+dim_x-1,i),u(:,index)); 16 | index=index+1; 17 | end 18 | end 19 | 20 | 21 | %combine trajectories 22 | index_0 =1; 23 | index_1 =1; 24 | for j=1:dim_x:initpoints*dim_x 25 | for i=2:steps+1 26 | x_free_vec_1(:,index_1) = x_free(j:j+dim_x-1,i); 27 | index_1 = index_1 +1; 28 | end 29 | for i=1:steps 30 | x_free_vec_0(:,index_0) = x_free(j:j+dim_x-1,i); 31 | index_0 = index_0 +1; 32 | end 33 | end 34 | % x_free_vec_1= normalize(x_free_vec_1); 35 | % x_free_vec_0 = normalize(x_free_vec_0); 36 | % u = normalize(u); 37 | normType=2; 38 | for idx=1:dim_x 39 | L(idx) = [0]; 40 | gamma(idx) = 0; 41 | for i=1:totalsamples 42 | z1= [x_free_vec_0(idx,i);u(:,i)]; 43 | f1= x_free_vec_1(idx,i); 44 | for j=1:totalsamples 45 | z2= [x_free_vec_0(idx,j);u(:,j)]; 46 | f2= x_free_vec_1(idx,j); 47 | if z1~=z2 48 | newnorm = norm(f1-f2,normType)./norm(z1-z2,normType); 49 | newgamma = norm(z1-z2,normType); 50 | if newnorm > L(idx) 51 | L(idx) = newnorm; 52 | end 53 | if newgamma > gamma(idx) 54 | gamma(idx) = newgamma; 55 | end 56 | end 57 | end 58 | end 59 | 60 | end 61 | end 62 | 63 | % L = 0; 64 | % gamma = 0; 65 | % for i=1:totalsamples 66 | % z1= [x_free_vec_0(:,i);u(:,i)]; 67 | % f1= x_free_vec_1(:,i); 68 | % for j=1:totalsamples 69 | % z2= [x_free_vec_0(:,j);u(:,j)]; 70 | % f2= x_free_vec_1(:,j); 71 | % if z1~=z2 72 | % newnorm = norm(f1-f2)./norm(z1-z2); 73 | % newgamma = norm(z1-z2); 74 | % if newnorm(1) > L(1) 75 | % L(1) = newnorm(1); 76 | % end 77 | % % if newnorm(2) > L(2) 78 | % % L(2) = newnorm(2); 79 | % % end 80 | % if newgamma > gamma 81 | % gamma(1) = newgamma(1); 82 | % end 83 | % % if newgamma(2) > gamma 84 | % % gamma(2) = newgamma(2); 85 | % % end 86 | % end 87 | % end 88 | % end 89 | % eps(2)= L .* gamma; 90 | % end 91 | -------------------------------------------------------------------------------- /utilities/minBeta.m: -------------------------------------------------------------------------------- 1 | function Dksi = minBeta(obj) 2 | % ksi_optimizer - determine the tighend domains for the zonotope factors 3 | % ksi by solving a linear program 4 | % 5 | % Syntax: 6 | % Dksi = ksi_optimizer(obj) 7 | % 8 | % Inputs: 9 | % obj - constrained zonotope object 10 | % 11 | % Outputs: 12 | % Dksi - new tighend domains for the zonotope factors (class: interval) 13 | % 14 | % Other m-files required: none 15 | % Subfunctions: none 16 | % MAT-files required: none 17 | % 18 | % See also: --- 19 | % 20 | % References: 21 | % [1] J. Scott et al. "Constrained zonotope: A new tool for set-based 22 | % estimation and fault detection" 23 | 24 | % Author: Dmitry Grebenyuk, Niklas Kochdumper 25 | % Written: 11-May-2018 26 | % Last update: --- 27 | % Last revision:--- 28 | 29 | %------------- BEGIN CODE -------------- 30 | 31 | if ~isempty(obj.A) 32 | 33 | % object properties 34 | n = size(obj.A, 2); 35 | A = obj.A; 36 | b = obj.b; 37 | 38 | % ksi in [-1, 1] 39 | lb = -ones(n,1); 40 | ub = ones(n,1); 41 | 42 | % initialize ksi 43 | ksi_min = zeros(n,n); 44 | ksi_max = zeros(n,n); 45 | 46 | % options 47 | options = optimoptions('linprog','Algorithm','dual-simplex', 'display','off'); 48 | 49 | for i = 1:n 50 | 51 | % min/max ksi_i 52 | f = zeros(n, 1); 53 | f(i, 1) = 1; 54 | 55 | % minimize (Equation (25) in [1]) 56 | [x, ~, flag_min] = linprog(f,[],[],A,b,lb,ub,options); 57 | ksi_min(:,i) = x; 58 | 59 | % maximize (Equation (26) in [1]) 60 | [x, ~, flag_max] = linprog(-f,[],[],A,b,lb,ub,options); 61 | ksi_max(:,i) = x; 62 | %if flag_min ~= 1 || flag_max ~= 1 63 | % error('Optimization error') 64 | %end 65 | % if (flag_min ~= 1 && flag_min ~= 0) || (flag_max ~= 1 && flag_max ~= 0) 66 | % %for printing 67 | % minFlag = flag_min 68 | % maxFlag =flag_max 69 | % error('Optimization error') 70 | % end 71 | end 72 | 73 | % delete dublicates 74 | ksi = unique([ksi_min, ksi_max]','rows'); 75 | ksi = ksi'; 76 | 77 | % calculate tightend domain for the zonotope factors 78 | ksi_l = min(ksi,[],2); 79 | ksi_u = max(ksi,[],2); 80 | 81 | Dksi = interval(ksi_l,ksi_u); 82 | 83 | 84 | else % no constraints -> return unit-cube as domain for ksi 85 | 86 | n = size(obj.Z,2)-1; 87 | Dksi = interval(-ones(n,1),ones(n,1)); 88 | end 89 | 90 | end 91 | 92 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /utilities/polyFun.m: -------------------------------------------------------------------------------- 1 | function f = polyFun(x,u,T) 2 | 3 | f(1,1) = .320*x(1)^2 +u(1)+0.7*x(1) ;%+u(1)^2+u(2)^2; 4 | 5 | f(2,1) = .320*u(2)*x(1)+ 0.4*x(2)^2+0.09*x(1); 6 | 7 | end 8 | 9 | %------------- END OF CODE -------------- -------------------------------------------------------------------------------- /workspace/paper/run_3appIn10S2_0_005w_0_002v_red390.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/workspace/paper/run_3appIn10S2_0_005w_0_002v_red390.mat -------------------------------------------------------------------------------- /workspace/paper/run_poly.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/workspace/paper/run_poly.mat -------------------------------------------------------------------------------- /workspace/paper/run_poly2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/workspace/paper/run_poly2.mat -------------------------------------------------------------------------------- /workspace/paper/run_poly3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/workspace/paper/run_poly3.mat -------------------------------------------------------------------------------- /workspace/paper/run_side001In10S3_0_005w_red200.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aalanwar/Data-Driven-Reachability-Analysis/c13e22ba46823218166258e29abd5ae2ddbc53af/workspace/paper/run_side001In10S3_0_005w_red200.mat --------------------------------------------------------------------------------