How to turn OFF display message of lsqr function

20 vues (au cours des 30 derniers jours)
Benoit
Benoit le 9 Oct 2024
Commenté : Arjun le 9 Oct 2024
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);
Error using max
First input array is an invalid data type.

Error in lsqr (line 122)
maxit = max(maxit, 0);
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,

Réponse acceptée

Arjun
Arjun le 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!
  2 commentaires
Benoit
Benoit le 9 Oct 2024
As simple as that... Thank you !
Arjun
Arjun le 9 Oct 2024
You are welcome!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Design Optimization dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by