how i can run least squares (LS) criterion algorithm on this data?

6 次查看(过去 30 天)
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);

回答(1 个)

Matt J
Matt J 2021-5-6
编辑:Matt J 2021-5-6
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 个评论
mohammad nemat
mohammad nemat 2021-5-6
I want to implement the least squares (LS) criterion algorithm for x1 and x2 . what is the output of this code and how it is solve the problem?
Matt J
Matt J 2021-5-6
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')

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Thermal Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by