ERROR:NOT ENOUGH INPUT ARGUMENT IN LINE n = length(y);
Show older comments
% parse arguments
params = {2, 0.7, 10, 8e-4, 1e-2, 'quadprog'};
i = ~cellfun(@isempty, varargin);
params(i) = varargin(i);
[tau0, tau1, delta_knot, alpha, gamma, solver] = deal(params{:});
n = length(y);
y = y(:);
% bateman ARMA model
a1 = 1/min(tau1, tau0); % a1 > a0
a0 = 1/max(tau1, tau0);
ar = [(a1*delta + 2) * (a0*delta + 2), 2*a1*a0*delta^2 - 8, ...
(a1*delta - 2) * (a0*delta - 2)] / ((a1 - a0) * delta^2);
ma = [1 2 1];
% matrices for ARMA model
i = 3:n;
A = sparse([i i i], [i i-1 i-2], repmat(ar, n-2, 1), n, n);
M = sparse([i i i], [i i-1 i-2], repmat(ma, n-2, 1), n, n);
% spline
delta_knot_s = round(delta_knot / delta);
spl = [1:delta_knot_s delta_knot_s-1:-1:1]'; % order 1
spl = conv(spl, spl, 'full');
spl = spl / max(spl);
% matrix of spline regressors
i = bsxfun(@plus, (0:length(spl)-1)'-floor(length(spl)/2), 1:delta_knot_s:n);
nB = size(i, 2);
j = repmat(1:nB, length(spl), 1);
p = repmat(spl(:), 1, nB);
valid = i >= 1 & i <= n;
B = sparse(i(valid), j(valid), p(valid));
% trend
C = [ones(n,1) (1:n)'/n];
nC = size(C, 2);
% Solve the problem:
% .5*(M*q + B*l + C*d - y)^2 + alpha*sum(A,1)*p + .5*gamma*l'*l
% s.t. A*q >= 0
if strcmpi(solver, 'quadprog')
% Use Matlab's quadprog
H = [M'*M, M'*C, M'*B; C'*M, C'*C, C'*B; B'*M, B'*C, B'*B+gamma*speye(nB)];
f = [alpha*sum(A,1)'-M'*y; -(C'*y); -(B'*y)];
[z, obj] = quadprog(H, f, [-A zeros(n,length(f)-n)], zeros(n, 1), ...
[], [], [], [], [], optimset('Algorithm', 'interior-point-convex', ...
'TolFun', 1e-13));
%z = qp([], H, f, [], [], [], [], zeros(n,1), [A zeros(n,length(f)-n)], []);
obj = obj + .5 * (y' * y);
elseif strcmpi(solver, 'sedumi')
% Use SeDuMi
U = [A, sparse(n,nC), -speye(n), sparse(n,n+nB+4); ...
M, C, sparse(n,n+2), -speye(n), sparse(n,2), B; ...
sparse(1,2*n+nC), 1, sparse(1,n+nB+3); ...
sparse(1,3*n+nC+2), 1, sparse(1,nB+1)];
b = [sparse(n,1); y; 1; 1];
c = sparse([n+nC+(1:n), 2*n+nC+2, 3*n+nC+4], ...
1, [alpha*ones(1,n), 1, gamma], 3*n+nC+nB+4, 1);
K = struct('f', n+nC, 'l', n, 'r', [2+n 2+nB]);
pars.eps = 1e-6;
pars.chol.maxuden = 1e2;
z = sedumi(U, b, c, K, pars);
obj = c' * z;
%objd = b' * s;
end
l = z(end-nB+1:end);
d = z(n+1:n+nC);
t = B*l + C*d;
q = z(1:n);
p = A * q;
r = M * q;
e = y - r - t;
end
Answers (1)
Cris LaPierre
on 20 Feb 2021
Edited: Cris LaPierre
on 20 Feb 2021
0 votes
Based on what you've shared, you are trying to take the length of a variable that doesn't yet exist (y). That would give a different error, though, so perhaps you've left something out?
I suggest also sharing the entire error message (all the red text).
8 Comments
NUR BATRISYIA HANNANI ZAIN AZMI
on 21 Feb 2021
Walter Roberson
on 21 Feb 2021
You invoked the function without passing any parameters to it. What is your expectation of where it should look to find content for the variable that the function refers to as y?
NUR BATRISYIA HANNANI ZAIN AZMI
on 10 Mar 2021
Walter Roberson
on 10 Mar 2021
y = randn(1,150);
delta = 3;
cvxEDA(y, delta)
NUR BATRISYIA HANNANI ZAIN AZMI
on 16 Mar 2021
Cris LaPierre
on 16 Mar 2021
Edited: Cris LaPierre
on 16 Mar 2021
Provide the inputs you have written into your function declaration
function [r, p, t, l, d, e, obj] = cvxEDA(y, delta, varargin)
^^ ^^^^^ % These first two inputs are required
When you try to use cvxEDA, you must pass in values for y and delta.
NUR BATRISYIA HANNANI ZAIN AZMI
on 16 Mar 2021
Cris LaPierre
on 16 Mar 2021
You should really read though the page I linked you to. The examples show you how to write a function, and then how to use that function.
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!