How to turn OFF display message of lsqr function

22 次查看(过去 30 天)
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,

采纳的回答

Arjun
Arjun 2024-10-9
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Design Optimization 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by