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

9 visualizaciones (últimos 30 días)
mohammad nemat
mohammad nemat el 6 de Mayo de 2021
Comentada: Matt J el 6 de Mayo de 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);

Respuestas (1)

Matt J
Matt J el 6 de Mayo de 2021
Editada: Matt J el 6 de Mayo de 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 comentarios
mohammad nemat
mohammad nemat el 6 de Mayo de 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 el 6 de Mayo de 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')

Iniciar sesión para comentar.

Categorías

Más información sobre Thermal Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by