Hello Ali,
To plot a Polyhedron, the 'fimplicit' function can be utilized. More details about this function are available in this documentation: https://www.mathworks.com/help/matlab/ref/fimplicit.html.
Here is an example demonstrating how to plot a Polyhedron using the 'fimplicit' function for 'n'=2:
- Start by initializing the matrix 'A' and 'b'.
A = [1, 2; -1, 2; 0, -1];
b = [3; 1; 0];
figure;
hold on;
- Use the 'fimplicit' function to plot the inequality equations.
fimplicit(@(x, y) A(1,1)*x + A(1,2)*y - b(1), 'r', 'LineWidth', 1);
fimplicit(@(x, y) A(2,1)*x + A(2,2)*y - b(2), 'g', 'LineWidth', 1);
fimplicit(@(x, y) A(3,1)*x + A(3,2)*y - b(3), 'b', 'LineWidth', 1);
- Finally, plot the Polyhedron, as shown in below code snippet.
xlim([-5, 5]);
ylim([-5, 5]);
xlabel('x');
ylabel('y');
title('Feasible Region for Ax \geq b');
grid on;
hold off;
Similarly, for 'n'=3, the inequalities can be plotted using the 'fimplicit3' function, as illustrated in the code snippet below. For more information on this function, refer to this documentation: https://www.mathworks.com/help/matlab/ref/fimplicit3.html.
fimplicit3(@(x, y, z) A(1,1)*x + A(1,2)*y + A(1,3)*z - b(1), 'r', 'FaceAlpha', 0.5);
fimplicit3(@(x, y, z) A(2,1)*x + A(2,2)*y + A(2,3)*z - b(2), 'g', 'FaceAlpha', 0.5);
fimplicit3(@(x, y, z) A(3,1)*x + A(3,2)*y + A(3,3)*z - b(3), 'b', 'FaceAlpha', 0.5);