How to use lsqr matlab function to minimize a cost function?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Zuber Khan
2024-5-8
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!