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 Center および File ExchangeCalendar についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by