How can I plot Polyhedra

11 次查看(过去 30 天)
Ali Shahmoradi
Ali Shahmoradi 2023-4-24
回答: Tejas 2024-10-23,9:42
Let and . if , How can I plot H when or ?

回答(1 个)

Tejas
Tejas 2024-10-23,9:42
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 中查找有关 Bounding Regions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by