how i can run least squares (LS) criterion algorithm on this data?
7 views (last 30 days)
Show older comments
x1=[0.1 , 1.1 ;
6.8 , 7.1 ;
-3.5 , -4.1 ;
2 , 2.7 ;
4.1 , 2.8 ;
3.1 , 5 ;
-0.8 , -1.3 ;
0.9 , 1.2 ;
5 , 6.4 ;
3.9 , 4 ;
];
x2=[7.1 , 4.2 ;
-1.4 , -4.3 ;
4.5 , 0 ;
6.3 , 1.6 ;
4.2 , 1.9 ;
1.4 , -3.2 ;
2.4 , -4 ;
2.5 , -6.1 ;
8.4 , 3.7 ;
4.1 , -2.2 ;
];
%x = lsqr(A,b);
[x,flag,relres,iter,resvec,lsvec] = lsqr(x1,x2,1e-4,70);
N = length(resvec);
semilogy(0:N-1,lsvec,'--o',0:N-1,resvec,'-o')
legend("Least-squares residual","Relative residual")
I want to run least squares (LS) criterion algorithm on this data with function lsqr but i get this error please help me .if you have any solution for run least squares please tell.
error
Error using lsqr (line 88)
Right hand side must be a column vector.
Error in lsq (line 25)
[x,flag,relres,iter,resvec,lsvec] = lsqr(x1,x2,1e-4,70);
0 Comments
Answers (1)
Matt J
on 6 May 2021
Edited: Matt J
on 6 May 2021
Maybe as follows,
for i=1:size(x2,2)
[c(:,i),flag,relres,iter,resvec(:,i),lsvec(:,i)] = lsqr(x1,x2(:,i),1e-4,70);
end
2 Comments
Matt J
on 6 May 2021
what is the output of this code
See below,
x1=[0.1 , 1.1 ;
6.8 , 7.1 ;
-3.5 , -4.1 ;
2 , 2.7 ;
4.1 , 2.8 ;
3.1 , 5 ;
-0.8 , -1.3 ;
0.9 , 1.2 ;
5 , 6.4 ;
3.9 , 4 ;
];
x2=[7.1 , 4.2 ;
-1.4 , -4.3 ;
4.5 , 0 ;
6.3 , 1.6 ;
4.2 , 1.9 ;
1.4 , -3.2 ;
2.4 , -4 ;
2.5 , -6.1 ;
8.4 , 3.7 ;
4.1 , -2.2 ;
];
for i=1:size(x2,2)
[c(:,i),flag,relres,iter,resvec(:,i),lsvec(:,i)] = lsqr(x1,x2(:,i),1e-4,70);
end
N = length(resvec);
semilogy(0:N-1,lsvec,'--o',0:N-1,resvec,'-o')
legend("Least-squares residual x2(:,1)","Least-squares residual x2(:,2)",...
"Relative residual x2(:,1)", "Relative residual x2(:,2)",'Location','southwest')
See Also
Categories
Find more on Mathematics and Optimization 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!