Plot functions and intersections

조회 수: 5 (최근 30일)
Harel Harel Shattenstein
Harel Harel Shattenstein 2019년 5월 27일
답변: Star Strider 2019년 5월 27일
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에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by