forked from cvxr/TFOCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmooth_constant.m
29 lines (25 loc) · 944 Bytes
/
smooth_constant.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function op = smooth_constant( d )
%SMOOTH_CONSTANT Constant function generation.
% FUNC = SMOOTH_CONSTANT( D ) returns a function handle that provides
% a TFOCS-compatible implementation of the constant function F(X) = D.
% D must be a real scalar. The function can be used in both a smooth
% and a nonsmooth context.
error(nargchk(1,1,nargin));
if ~isa( d, 'double' ) || ~isreal( d ) || numel( d ) ~= 1,
error( 'Argument must be a real scalar.' );
end
op = @(varargin)smooth_constant_impl( d, varargin{:} );
function [ v, g ] = smooth_constant_impl( v, x, t )
switch nargin,
case 2,
if nargin > 1,
g = 0 * x;
end
case 3,
g = x;
otherwise,
error( 'Not enough arguments.' );
end
% TFOCS v1.3 by Stephen Becker, Emmanuel Candes, and Michael Grant.
% Copyright 2013 California Institute of Technology and CVX Research.
% See the file LICENSE for full license information.