|
| 1 | +import py.codac4matlab.* |
| 2 | + |
| 3 | +a=Interval(-1,2) |
| 4 | +a.lb |
| 5 | +a.ub |
| 6 | + |
| 7 | +x=[1,2] |
| 8 | +X=IntervalVector(x) |
| 9 | +X.size |
| 10 | +X(2) |
| 11 | +X(2).init(Interval(-10,10)) |
| 12 | +X |
| 13 | + |
| 14 | +x={{-5,5},{-4,4}} |
| 15 | +X=IntervalVector(x) |
| 16 | +X.size |
| 17 | + |
| 18 | +M=[1,2;3,4;5,6] |
| 19 | +C=arrayfun(@(i) num2cell(M(i,:)), 1:size(M,1), 'UniformOutput', false); % Inverse operation would be cell2mat(vertcat(C{:})) |
| 20 | +A=IntervalMatrix(Matrix(C)) |
| 21 | +A.rows |
| 22 | +A.cols |
| 23 | +A(3,2) |
| 24 | +A(3,2).init(Interval(-10,10)) |
| 25 | +A.set_item({1,2},Interval(11,12)) |
| 26 | +A |
| 27 | + |
| 28 | +A_lb = Matrix({{-1,-2},{-3,-4},{-5,-6}}); |
| 29 | +A_ub = Matrix({{1,2},{3,4},{5,6}}); |
| 30 | +A=IntervalMatrix(A_lb,A_ub) |
| 31 | +A.rows |
| 32 | +A.cols |
| 33 | +A(3,2) |
| 34 | + |
| 35 | +A_ub.set_item({1,2},10) |
| 36 | +A_ub |
| 37 | + |
| 38 | +function C = Matrix2cell(M) |
| 39 | + import py.codac4matlab.* |
| 40 | + r = int32(M.rows); |
| 41 | + c = int32(M.cols); |
| 42 | + C = cell(1,r); |
| 43 | + for i=1:r |
| 44 | + rl = cell(1,c); |
| 45 | + for j=1:c |
| 46 | + rl{j} = double(M(i,j)); |
| 47 | + end |
| 48 | + C{i} = rl; |
| 49 | + end |
| 50 | +end |
| 51 | + |
| 52 | +%M=Matrix({{1,2},{3,4},{5,6}}) |
| 53 | +%Matrix2cell(M) |
| 54 | +%return |
| 55 | + |
| 56 | +% It seems we cannot do A(i,j).init(x) if A is a Matrix... But we can do |
| 57 | +% A.set_item({i,j},x)... |
| 58 | +function B = setitemM(A,i,j,x) |
| 59 | +%SETITEMM Set element (i,j) of a Codac Matrix. |
| 60 | +% |
| 61 | +% B = setitemM(A,i,j,x) |
| 62 | +% |
| 63 | +% A : Codac Matrix |
| 64 | +% i : row index (1-based MATLAB indexing) |
| 65 | +% j : column index (1-based MATLAB indexing) |
| 66 | +% x : double |
| 67 | + |
| 68 | + import py.codac4matlab.* |
| 69 | + C = Matrix2cell(A); |
| 70 | + C{i}{j} = x; |
| 71 | + B = Matrix(C); |
| 72 | +end |
| 73 | + |
| 74 | +% Does the same as A(i,j).init(x), probably in a slower way... |
| 75 | +function B = setitemIM(A,i,j,x) |
| 76 | +%SETITEMIM Set element (i,j) of a Codac IntervalMatrix. |
| 77 | +% |
| 78 | +% B = setitemIM(A,i,j,x) |
| 79 | +% |
| 80 | +% A : Codac IntervalMatrix |
| 81 | +% i : row index (1-based MATLAB indexing) |
| 82 | +% j : column index (1-based MATLAB indexing) |
| 83 | +% x : Codac Interval |
| 84 | + |
| 85 | + import py.codac4matlab.* |
| 86 | + C_lb = Matrix2cell(A.lb); |
| 87 | + C_lb{i}{j} = x.lb; |
| 88 | + C_ub = Matrix2cell(A.ub); |
| 89 | + C_ub{i}{j} = x.ub; |
| 90 | + B = IntervalMatrix(Matrix(C_lb),Matrix(C_ub)); |
| 91 | +end |
| 92 | + |
| 93 | +A = Matrix({{1,2},{3,4},{5,6}}); |
| 94 | +A = setitemM(A,3,2,99) |
| 95 | + |
| 96 | +A(3,2) |
| 97 | +A |
| 98 | + |
| 99 | +A_lb = Matrix({{-1,-2},{-3,-4},{-5,-6}}); |
| 100 | +A_ub = Matrix({{1,2},{3,4},{5,6}}); |
| 101 | +A = IntervalMatrix(A_lb,A_ub); |
| 102 | + |
| 103 | +A = setitemIM(A,2,1,Interval(100,200)); |
| 104 | + |
| 105 | +A(2,1) |
| 106 | +A |
0 commit comments