From c5cdd03fc0588f7d34d8b97713caa6d19e5becea Mon Sep 17 00:00:00 2001 From: YanzhenXiangRobotics Date: Wed, 10 May 2023 23:13:51 +0200 Subject: ADD: pass task 25 --- templates/chebycenter.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 templates/chebycenter.m (limited to 'templates/chebycenter.m') diff --git a/templates/chebycenter.m b/templates/chebycenter.m new file mode 100755 index 0000000..cbdce1c --- /dev/null +++ b/templates/chebycenter.m @@ -0,0 +1,20 @@ +function [c,r] = chebycenter(A,b) +%CHEBYCENTER Compute Chebyshev center of polytope Ax <= b. +% The Chebyshev center of a polytope is the center of the largest +% hypersphere enclosed by the polytope. +% Requires optimization toolbox. + +[n,p] = size(A); +an = sqrt(sum(A.^2,2)); +A1 = zeros(n,p+1); +A1(:,1:p) = A; +A1(:,p+1) = an; +f = zeros(p+1,1); +f(p+1) = -1; + +options = optimset; +options = optimset(options,'Display', 'off'); +c = linprog(f,A1,b,[],[],[],[],[],options); +r = c(p+1); +c = c(1:p); +end -- cgit v1.2.1