Con2vert with 5 dimensions Error: Arrays have incompatible sizes for this operation.

2 views (last 30 days)
I'm trying to find vertices/plot feasible region of the inequality equations (A,b) below but an error of Arrays have incompatible sizes for this operation occurred. Can someone help me debug this? Thanks so much.
function [V,nr] = con2vert(A,b);
A = [0 1 0 1 1; 1 0 0 0 0; -1 -3 1 -3 0; 2 0 -1 3 -6; 0 -1 0 0 0; 0 0 -1 0 0; 0 0 0 -1 0; 0 0 0 0 -1];
b = [1; 0.5; 0; 0; 0; 0; 0; 0];
figure('renderer','zbuffer')
hold on
[x,y]=ndgrid(-3:.01:5);
p=[x(:) y(:)]';
p=(A.*p <= repmat(b,[10 length(p)]));
p = double(all(p));
p=reshape(p,size(x));
h=pcolor(x,y,p);
set(h,'edgecolor','none')
set(h,'zdata',get(h,'zdata')-1) % keep in back
axis equal
V=con2vert(A,b);
%p = convhull(x,y);
plot(V(:,1),V(:,2),'y.')

Accepted Answer

Matt J
Matt J on 28 Mar 2023
Edited: Matt J on 28 Mar 2023
I recommend using lcon2vert instead,
A = [0 1 0 1 1; 1 0 0 0 0; -1 -3 1 -3 0; 2 0 -1 3 -6; 0 -1 0 0 0; 0 0 -1 0 0; 0 0 0 -1 0; 0 0 0 0 -1];
b = [1; 0.5; 0; 0; 0; 0; 0; 0];
V=lcon2vert(A,b)
V =
-3.0000 0 0 1.0000 0
-3.0000 1.0000 0 0 0
-1.5000 0 0 1.0000 0
0 0 0 0 0
0 0 0 0 1.0000
-0.0000 0 3.0000 1.0000 0
-0.0000 1.0000 0 0 0
0.5000 0 0 0 0.1667
0.5000 0 0 0 1.0000
0.5000 0 0 0.5556 0.4444
0.5000 0 0.5000 0 0.0833
0.5000 0 0.5000 0 1.0000
0.5000 0 3.2500 0.9167 0.0833
0.5000 0.1667 1.0000 0 0
0.5000 0.1667 3.5000 0.8333 0
0.5000 0.8333 0 0 0.1667
0.5000 1.0000 1.0000 0 0
0.5000 1.0000 3.5000 0 0
However, how you expect to plot a 5-D region is unclear. You know that we live in a 3-D universe, right?

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!