How can I plot Polyhedra

조회 수: 5 (최근 30일)
Ali Shahmoradi
Ali Shahmoradi 2023년 4월 24일
답변: Tejas 2024년 10월 23일
Let and . if , How can I plot H when or ?

답변 (1개)

Tejas
Tejas 2024년 10월 23일
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);

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by