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

조회 수: 5 (최근 30일)
mohammad nemat
mohammad nemat 2021년 5월 6일
댓글: Matt J 2021년 5월 6일
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