How to use lsqr matlab function to minimize a cost function?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
x=argmin(||(Ax-b)c||^2+||e(x-d)||^2), Where A is a mxn matrix, c,d,e are vectors. How to write this function using lsqr inbuilt matlab function?
x=lsqr(A,b,tol,maxit). Here how to insert value of c,d,e?
0 comentarios
Respuestas (1)
Zuber Khan
el 8 de Mayo de 2024
Hi,
I understand that you want to minimize the given cost function using "lsqr" method.
Note that 'lsqr(A,b)' attempts to solve the system of linear equations A*x = b for x using the Least Squares Method.
Now firstly, your optimzation problem can be seen as a combination of two least squares problems. However, "lsqr" cannot directly solve it in the given form because of the additional vectors 'c', 'd', and 'e', and the way they interact with 'x'.
A common approach to deal with additional linear terms in a least squares problem is to augment the matrix 'A' and vector 'b' to incorporate these terms, turning the problem into a standard form that "lsqr" can solve. However, this is not a straightforward approach since you would need to take care of the dimensionality and ensure that the resulting equation A*x = b consisting of augmented arrays 'A' and 'b', truly represents the original form of the problem.
Alternatively, a better way would be to use appropriate solvers like "fminunc" or "lsqnonlin" for your use case. For instance, the given problem can be tackled using "fminunc" as follows:
% Define the cost function
costFunc = @(x) norm((A*x - b)*c)^2 + norm(e*(x - d))^2;
% Initial guess for x
x0 = zeros(n, 1);
% Minimize the cost function
x = fminunc(costFunc, x0);
For more information related to "fminunc" solver, kindly refer to the following documentation link:
Further, in order to explore "lsqnonlin" solver, kindly refer to the documentation link mentioned below:
I hope this will resolve your query.
Regards,
Zuber
0 comentarios
Ver también
Categorías
Más información sobre Mathematics and Optimization en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!