-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotMeasuresonDomain.m
146 lines (131 loc) · 4.56 KB
/
plotMeasuresonDomain.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function C = plotMeasuresOnDomain(argument,W,x,Rx,color)
%disp('Pcontour');
global slice4DAt
hold on;
gridStep=0.01;
if isempty(slice4DAt)
slice4DAt=zeros(4,1);
end
if ~exist('color', 'var')
if strcmp(argument, 'W')
color = 'r';
elseif strcmp(argument, 'V')
color = 'b';
end
end
%disp('p');
linewidth=4;
linespec = color;
% linespec=['-' color];
switch size(x,1) %Plot Based on the dimention
case 1
temp = [];
if numel(Rx) ~= 2
disp('ERROR: WRONG NUMBER OF RX');
end
x1 = Rx(1):0.01:Rx(2);
for i=1:numel(x1)
temp(i) = subs(W, x, x1(i));
end
plot(x1, temp, linespec); hold on;
plot([Rx(1) -0.5 -0.5 0.5 0.5 Rx(2)], [0 0 1 1 0 0], 'r');
hold off;
case 2
if isa(W, 'sym')
problem = W;
else
x = sym('x',[2 1]);
problem=spot2syms(W, x);
if numel(Rx) ~= 4
disp('ERROR: WRONG NUMBER OF RX');
end
end
domain = [-1 1 -1 1] ;
[y1,y2] = meshgrid(Rx(1,1):gridStep:Rx(1,2),Rx(2,1):gridStep:Rx(2,2));
hold on;
if strcmp(argument, 'W')
pgrid = double(subs(problem,{'x1','x2'},{y1,y2}));
[c,h] = contour(y1,y2,pgrid,[1,1],linespec);
elseif strcmp(argument, 'V')
pgrid = double(subs(problem,{'x1','x2','t'},{y1,y2,0}));
[c,h] = contour(y1,y2,pgrid,[0,0],linespec);
end
set(h,'linewidth',2);
xlabel('x1');
ylabel('x2');
axis (domain);
y1V = y1(:);
y2V = y2(:);
val = pgrid(:);
idx = find(val >= 1);
C.samplePts = [y1V(idx), y2V(idx)];
C.edges = c;
idxNotIn = find(val >= 0.95 & val < 1);
C.narrowlyNotIn = [y1V(idxNotIn), y2V(idxNotIn)];
case 4
w=sdisplay(W);
x=sdisplay(x);
if numel(Rx) == 1
Rx = [Rx Rx];
end
domain = [-Rx(1) Rx(1) -Rx(2) Rx(2)] ;
%disp('2D Problem');
[y1,y2] = meshgrid(-Rx(1):gridStep:Rx(1),-Rx(2):gridStep:Rx(2));
problem = w{1};
problem = strrep(problem,'x(1)','x1');
problem = strrep(problem,'x(2)','x2');
problem = strrep(problem,'x(3)','0');
problem = strrep(problem,'x(4)','0');
problem = sym(problem);
hold on;
C = [];
if strcmp(argument, 'W')
pgrid = double(subs(problem,{'x1','x2'},{y1,y2}));
contour(y1,y2,pgrid,[1,1],linespec);
elseif strcmp(argument, 'V')
pgrid = double(subs(problem,{'x1','x2','t'},{y1,y2,0}));
contour(y1,y2,pgrid,[0,0],linespec);
end
%pgrid1 = pgrid >= 1 ;
%contourf(y1,y2,pgrid1,[1,1],linespec);
% use contourf?
C.y1 = y1;
C.y2 = y2;
C.pgrid = pgrid;
xlabel('x1');
ylabel('x2');
axis (domain);
% w=sdisplay(W);
% x=sdisplay(x);
% if numel(Rx) == 1
% Rx = [Rx Rx];
% end
% domain = [-Rx(1) Rx(1) -Rx(2) Rx(2)] ;
% %disp('2D Problem');
% [y1,y2,y3,y4] = ndgrid(-Rx(1):gridStep:Rx(1),-Rx(2):gridStep:Rx(2),-Rx(3):gridStep:Rx(3),-Rx(4):gridStep:Rx(4) );
% problem = w{1};
% problem = strrep(problem,'x(1)','x1');
% problem = strrep(problem,'x(2)','x2');
% problem = strrep(problem,'x(3)','x3');
% problem = strrep(problem,'x(4)','x4');
% problem = sym(problem);
%
% hold on;
% C = [];
% if strcmp(argument, 'W')
% pgrid = double(subs(problem,{'x1','x2','x3','x4'},{y1,y2,y3,y4}));
% contour(y1,y2,pgrid,[1,1],linespec);
% elseif strcmp(argument, 'V')
% pgrid = double(subs(problem,{'x1','x2','x3','x4','t'},{y1,y2,y3,y4,0}));
% contour(y1,y2,pgrid,[0,0],linespec);
% end
% %pgrid1 = pgrid >= 1 ;
% %contourf(y1,y2,pgrid1,[1,1],linespec);
% % use contourf?
% C.y1 = y1;
% C.y2 = y2;
% C.pgrid = pgrid;
% xlabel('x1');
% ylabel('x2');
% axis (domain);
end