Plot functions and intersections

3 visualizaciones (últimos 30 días)
Harel Harel Shattenstein
Harel Harel Shattenstein el 27 de Mayo de 2019
Respondida: Star Strider el 27 de Mayo de 2019
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)

Respuestas (1)

Star Strider
Star Strider el 27 de Mayo de 2019
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.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by