How make a graphic with only equations ?

1 view (last 30 days)
luis alfonso
luis alfonso on 4 Sep 2014
Edited: Joseph Cheng on 4 Sep 2014
In linear programming , a mathematical model is defined with a set of constraints, a polygon is the result of these constraints (equations)
can mathlab I always make a plot with points (x,y) but I not work with only the equations
  1 Comment
Joseph Cheng
Joseph Cheng on 4 Sep 2014
Can you give a simple example of what you are trying to accomplish?

Sign in to comment.

Answers (1)

Joseph Cheng
Joseph Cheng on 4 Sep 2014
Edited: Joseph Cheng on 4 Sep 2014
if you have MuPad Notebook (part of the symbolic toolbox?) you can use it like here http://www.mathworks.com/help/symbolic/mupad_ref/linopt-plot_data.html
or my example here:
%%Constraints
% maximise Z = 20x + 10y
% 10x +5y <=50
% 6x + 10y <=60
% 4x+12y<=48
% x,y>=0
%below portion done in MuPad
k := [{10*x +5*y <=50, 6*x + 10*y <=60, 4*x+12*y<=48},20*x+10*y,NonNegative]:
g := linopt::plot_data(k, [x, y]):
plot(g):
  1 Comment
Joseph Cheng
Joseph Cheng on 4 Sep 2014
Edited: Joseph Cheng on 4 Sep 2014
I've been thinking about what if you don't have MuPad well this is what i've got so far.
%%Constraints
% maximise Z = 20x + 10y
% 10x +5y <=50
% 6x + 10y <=60
% 4x+12y<=48
% 10x+y>=10 % unlike above my @ functions couldn't handle the infinity slope
% x+10y>=10 %
% x,y>=0
CV{1} = [0 10;5 0]; %constraintvertices 1
CV{2} = [0 6;10 0]; %constraintvertices 2
CV{3} = [0 4;12 0]; %constraintvertices 3
CV{4} = [0 10;1 0];
CV{5} = [0 1;10 0];
figure;hold all
for ind = 1:length(CV)
h(ind) = plot(CV{ind}(:,1),CV{ind}(:,2));
end
set(h,'linewidth',2)
axis([0 10 0 12])
slope = @(line) (line(2,2) - line(1,2))/(line(2,1) - line(1,1));
intercept = @(line,m) line(1,2) - m*line(1,1);
point = 1;
for ind = 1:length(CV)-1
for jnd = ind+1:length(CV)
m1 = slope(CV{ind});
m2 = slope(CV{jnd});
b1 = intercept(CV{ind},m1);
b2 = intercept(CV{jnd},m2);
xintersect(point) = (b2-b1)/(m1-m2);
yintersect(point) = m1*xintersect(point) + b1;
point = point+1;
end
end
plot(xintersect,yintersect,'r*','markersize',20)
Now you have a list of the all the intersections. Next step is to find the overlapping feasible region and remove the intersections that do not define the feasible region.
*update*
%left hand side coefficients, -1 for <= +1 for >=, then right hand side
Const = [10 5 -1 50;6 10 -1 60;4 12 -1 48;10 1 1 10; 1 10 1 10];
for ind = 1:length(Const)
switch Const(ind,3)
case -1
Fease(ind,:) = round(Const(ind,1)*xintersect+Const(ind,2)*yintersect) <= Const(ind,4);
case 1
Fease(ind,:) = round(Const(ind,1)*xintersect+Const(ind,2)*yintersect) >= Const(ind,4);
end
end
%valid corner if all constraints are met
corners = find(sum(Fease)/length(Const)==1)
plot(xintersect(corners),yintersect(corners),'bo','markersize',20)
i'll let you figure out how to fill in the poly and how to get rid of the minute error involved in x and y intersect points which causes the inequalities to fail. Ideally if we check each intersect to be valid for each constraint then we mark it good.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!