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

6 Ansichten (letzte 30 Tage)
mohammad nemat
mohammad nemat am 6 Mai 2021
Kommentiert: Matt J am 6 Mai 2021
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);

Antworten (1)

Matt J
Matt J am 6 Mai 2021
Bearbeitet: Matt J am 6 Mai 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 Kommentare
mohammad nemat
mohammad nemat am 6 Mai 2021
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 am 6 Mai 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')

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Thermal Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by