Parameter estimation

Please help me, when I use CVX to find theta1, I got accurate estimation, however when I tried to find theta i.e. evolution of theta, the result was incorect. CVX did not work for nonstationary parameter, is it ?

%Code
load('data.mat')
y=data(:,1);
u=data(:,2);
%%%%%%%%%%%%%%%%%%%%%%
Y=y(3:end);
phi_y= [-y(2:end-1)  -y(1:end-2)];
phi_u= [u(2:end-1)  u(1:end-2)];
Phi=[phi_y phi_u];
[N n]=size(Phi);
 cvx_begin
    variable theta1(n)
    minimize( norm((Y-Phi* theta1)))        
    cvx_end  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% building X
X=zeros(N,N* n);
for i=1:N
    X(i,:)=[zeros(1,n*(i-1)) Phi(i,: )  zeros(1,n*N-n*(i-1)-n)];
end 
    cvx_begin
    variable theta(n,N)
    minimize( norm((Y-X*theta(:))))        
    cvx_end   
figure(2)
plot(-squeeze(theta(1,:)),'--','linewidth',2)

Not all forum readers have the mind reading powers you perhaps assume we do. I assume CVX solved the problems you provided it. Whether the problems provided to CVX correspond to the statistical problems you wanted to solve is another matter.

I don’t know what you are trying to do. Do you intend for the 2nd version to be stacking a bunch of independent least norm problems together into one problem? I don’t see how that could be so, given that you have the same column vector Y in both versions occurring within a single norm, but in the 1st version there is only a column vector theta1, as opposed to a matrix theta in the 2nd version, “going up against” the column vector Y.

Does the stacking in X make any sense? I’ll let you figure that out. Perhaps you should start off simply, with N = 1. Then try N = 2, and make sure that does what you want before you try the value of N you really want.

Thanks for your reply, I modified the code to

for k=1:N
cvx_begin 
variable theta1(n)
minimize(norm((Y(1:k)-Phi(1:k,:)*theta1))^2)        
cvx_end  
Theta1(k,:)=theta1';
end

I got the requested result, just I would like to have it at once. Could you please give me how the function minimize solves the problem (in general). Thank you again

What’s wrong with the code you have? Use the quiet option if you want to suppress the output for each run of CVX.

You could declare theta as an n by N variable, move the for loop into CVX, and separately form the norm term for each value of k (with its corresponding column of theta). Then sum the norm terms and solve with a single minimize (or perhaps use sum_square rather than norm for the individual terms). That may or may not be faster than your existing code, but I doubt it would be much faster, if at all.