How can I plot Polyhedra

5 vues (au cours des 30 derniers jours)
Ali Shahmoradi
Ali Shahmoradi le 24 Avr 2023
Réponse apportée : Tejas le 23 Oct 2024
Let and . if , How can I plot H when or ?

Réponses (1)

Tejas
Tejas le 23 Oct 2024
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);

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by