Function handle in lsqr

3 ビュー (過去 30 日間)
Frank
Frank 2018 年 7 月 22 日
回答済み: Frank 2018 年 7 月 24 日
https://www.mathworks.com/help/matlab/ref/lsqr.html
In the above page, there is code: function y = afun(x,transp_flag) if strcmp(transp_flag,'transp') % y = A'*x y = 4 * x; y(1:n-1) = y(1:n-1) - 2 * x(2:n); y(2:n) = y(2:n) - x(1:n-1); elseif strcmp(transp_flag,'notransp') % y = A*x y = 4 * x; y(2:n) = y(2:n) - 2 * x(1:n-1); y(1:n-1) = y(1:n-1) - x(2:n); end end
Could anybody please kindly tell me what is the purpose of strcmp(transp_flag,'transp')? Why there have to be two kinds of transp_flag?

採用された回答

Steven Lord
Steven Lord 2018 年 7 月 22 日
The first paragraph in the Description section on that documentation page states:
"You can specify A as a function handle, afun, such that afun(x,'notransp') returns A*x and afun(x,'transp') returns A'*x."
By writing a function you may be able to solve systems where explicitly creating and storing A would require a lot of time and/or memory, but A has a structure that allows you to compute its product with a vector more efficiently without needing to build A. As an extreme case, if A was eye(1e6) that would require a lot of memory to store, but A*x and A'*x are each just x.
Why does lsqr require both those products? See page 44 as well as step 3 of the algorithm on page 50 of this paper which is the second reference on the lsqr documentation page.

その他の回答 (1 件)

Frank
Frank 2018 年 7 月 24 日
Thank you indeed for your very very specific answer to this question!

カテゴリ

Help Center および File ExchangeOceanography and Hydrology についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by