summaryrefslogtreecommitdiffstats
path: root/templates/chebycenter.m
diff options
context:
space:
mode:
authorYanzhenXiang <54230111+YanzhenXiangRobotics@users.noreply.github.com>2023-11-06 16:49:26 +0100
committerGitHub <noreply@github.com>2023-11-06 16:49:26 +0100
commitd6b96c55ebb89ebd6e2d990ec89122799c68a230 (patch)
tree7a837438da9e07a5e77658c6d882577fff8bcae1 /templates/chebycenter.m
parentUpdate 23 (diff)
parentupdate the new submission zip generated from npross branch (diff)
downloadmpc_pe-master.tar.gz
mpc_pe-master.zip
Merge pull request #1 from YanzhenXiangRobotics/submissionHEADmaster
Submission
Diffstat (limited to '')
-rwxr-xr-xtemplates/chebycenter.m20
1 files changed, 20 insertions, 0 deletions
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