Plot functions and intersections

3 次查看(过去 30 天)
Hi,
I am trying to plot a feasble area of a LP problem:
Max z=2*x1+2*x2
s.t
2*x1+x2 <= 16
3*x1+2*x2 <=25
2*x1+3*x2 <=25
x1+x2<=16
x1,x2>=0
I started with ploting the functions alone (without intersection points), but it seems that fplot does not work with multpile variables
fun1 = @(x1,x2) 2*x1 + x2 == 16;
fun2 = @(x1,x2) 3*x1 + 2*x2 == 25;
fun3 = @(x1,x2) 3*x1 + 3*x2 == 25;
fun4 = @(x1,x2) x1 + x2 == 16;
fplot(fun1)
hold on
fplot(fun2)
hold on
fplot(fun3)
hold on
fplot(fun4)

回答(1 个)

Star Strider
Star Strider 2019-5-27
The fsurf function takes two arguments:
figure
fsurf(fun1)
hold on
fsurf(fun2)
fsurf(fun3)
fsurf(fun4)
hold off
although you might find fcontour more applicable here:
func1 = @(x1,x2) 2*x1 + x2;
func2 = @(x1,x2) 3*x1 + 2*x2;
func3 = @(x1,x2) 3*x1 + 3*x2;
func4 = @(x1,x2) x1 + x2;
argrng = [-100 100 -100 100];
figure
fcontour(func1, argrng, 'LevelList',[1 1]*16)
hold on
fcontour(func2, argrng, 'LevelList',[1 1]*25)
fcontour(func3, argrng, 'LevelList',[1 1]*25)
fcontour(func4, argrng, 'LevelList',[1 1]*16)
hold off
Experiment to get the result you want.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by