liste vertex into polyhedron
5 次查看(过去 30 天)
显示 更早的评论
采纳的回答
更多回答(1 个)
Naga
2024-8-13
Hello Riccardo,
I understand that you are trying to list all the vertices of a polyhedron in MATLAB by solving the system of inequalities Ax<=b and x>=0. MATLAB does not have a built-in function specifically for listing all vertices of a polyhedron, but you can use the `linprog` function to find vertices.
1. Define the Polyhedron: Start with the matrix \(A\) and vector \(b\) that define your polyhedron.
2. Use `linprog` to Find Vertices: You can use linear programming to find the vertices by solving optimization problems for each combination of constraints.
Here is a MATLAB script to list all the vertices of a polyhedron:
function vertices = findPolyhedronVertices(A, b)
% Number of variables
n = size(A, 2);
% All combinations of constraints
combs = nchoosek(1:size(A, 1), n);
% Initialize an empty array to store the vertices
vertices = [];
% Solve for each combination of constraints
for i = 1:size(combs, 1)
% Select the constraints
A_eq = A(combs(i, :), :);
b_eq = b(combs(i, :));
% Solve the linear system A_eq * x = b_eq
x = A_eq \ b_eq;
% Check if the solution is feasible
if all(A * x <= b) && all(x >= 0)
% Add the vertex to the list
vertices = [vertices, x];
end
end
% Remove duplicate vertices
vertices = unique(vertices', 'rows')';
end
% Example usage:
A = [1 1; 1 -1; -1 0; 0 -1];
b = [2; 1; 0; 0];
vertices = findPolyhedronVertices(A, b);
% Display vertices in a readable format
disp('Vertices of the polyhedron:');
for i = 1:size(vertices, 2)
fprintf('Vertex %d: (%.4f, %.4f)\n', i, vertices(1, i), vertices(2, i));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computational Geometry 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!