Skip to content

Instantly share code, notes, and snippets.

@bnaul
Created June 22, 2016 06:17
Show Gist options
  • Save bnaul/e9a32a7cebad21f548358a4e3d27e24a to your computer and use it in GitHub Desktop.
Save bnaul/e9a32a7cebad21f548358a4e3d27e24a to your computer and use it in GitHub Desktop.
y = [0.1 0.2 0.1 0.2 0.5 0.4 0.6 0.7 0.8]';
p = length(y);
a = 0.2; b = 0.6;
A = tril(toeplitz([-1 1 zeros(1,p-2)]));
cvx_begin
variable x(p, 1)
minimize norm(x - y)
subject to
A * x <= 0
x(1) >= a
x(p) <= b
cvx_end
[x pava(y)]
%ans =
%
% 0.2000 0.1000
% 0.2000 0.1500
% 0.2000 0.1500
% 0.2000 0.2000
% 0.4500 0.4500
% 0.4500 0.4500
% 0.6000 0.6000
% 0.6000 0.7000
% 0.6000 0.8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment