How to turn OFF display message of lsqr function
22 views (last 30 days)
Show older comments
Hello folks,
I would like to turn off the display of the result of the least square method "lsqr" matlab function, such as:
"lsqr converged at iteration 5 to a solution with relative residual 0.086."
I asked to the AI and it gives me a example code. So this could be our test bench:
% Example of using lsqr with correct parameters
A = rand(100); % Example matrix
b = rand(100,1); % Example right-hand matrix
% Set options to turn off display and specify max iterations
options = optimset('Display', 'off', 'MaxIter', 100); % Ensure MaxIter is a positive integer
% Call lsqr with options
[x, flag] = lsqr(A, b, [], options);
The problem is that the code the AI generated does not work. There is and error with the input type optims.
If you have an idea on how to make this optimisation options work or another way to turn off the display of messages from lsqr function I would be thankfull !
Best for all,
0 Comments
Accepted Answer
Arjun
on 9 Oct 2024
I see that you want to turn off the display message of the “lsqr” function.
The “lsqr” function in MATLAB does not directly support the “optimset” functionality as it is not a part of Optimization Toolbox. To supress the display message, you can use an alternative approach i.e. when you specify the flag output, “lsqr” does not display any diagnostic messages.
To supress the display message use the following syntax:
[x,flag] = lsqr(…); % whenever flag is specified in output, no display message is printed
Refer to the code below for better understanding:
A = rand(100);
b = rand(100, 1);
% Set tolerance and maximum iterations
tol = 1e-6;
maxit = 100;
% No display messgae
[x, flag] = lsqr(A, b, tol, maxit);
The above code does not produce any display message.
Please refer to the documentation for better clarity: https://www.mathworks.com/help/matlab/ref/lsqr.html(under the example capturing flag output)
I hope this will help!
More Answers (0)
See Also
Categories
Find more on Simulink Design Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!