summaryrefslogtreecommitdiffstats
path: root/Submission files/chebycenter.m
diff options
context:
space:
mode:
authorYuan Xu <yuanxu@student.ethz.ch>2023-05-24 17:35:46 +0200
committerYuan Xu <yuanxu@student.ethz.ch>2023-05-24 17:35:46 +0200
commita23ba49056a36aff221d0c23e228b981222c3576 (patch)
tree742c18cbe13c1603909b55ee82188ce6360e8fa0 /Submission files/chebycenter.m
parentADD: declaration of originality (diff)
downloadmpc_pe-a23ba49056a36aff221d0c23e228b981222c3576.tar.gz
mpc_pe-a23ba49056a36aff221d0c23e228b981222c3576.zip
add submission zipsubmission
Diffstat (limited to '')
-rw-r--r--Submission files/chebycenter.m20
1 files changed, 20 insertions, 0 deletions
diff --git a/Submission files/chebycenter.m b/Submission files/chebycenter.m
new file mode 100644
index 0000000..cbdce1c
--- /dev/null
+++ b/Submission files/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