我是靠谱客的博主 温柔保温杯,最近开发中收集的这篇文章主要介绍matlab数据方块里面反斜杠,如何實現Matlab的mlb(即反斜杠運算符“\”),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

33

For x = Ab, the backslash operator encompasses a number of algorithms to handle different kinds of input matrices. So the matrix A is diagnosed and an execution path is selected according to its characteristics.

對於x = Ab,反斜杠運算符包含許多算法來處理不同類型的輸入矩陣。因此矩陣A被診斷出來,根據其特征選擇執行路徑。

The following page describes in pseudo-code when A is a full matrix:

當A是一個完整的矩陣時,下面的頁面用偽代碼描述:

if size(A,1) == size(A,2) % A is square

if isequal(A,tril(A)) % A is lower triangular

x = A b; % This is a simple forward substitution on b

elseif isequal(A,triu(A)) % A is upper triangular

x = A b; % This is a simple backward substitution on b

else

if isequal(A,A') % A is symmetric

[R,p] = chol(A);

if (p == 0) % A is symmetric positive definite

x = R (R' b); % a forward and a backward substitution

return

end

end

[L,U,P] = lu(A); % general, square A

x = U (L (P*b)); % a forward and a backward substitution

end

else % A is rectangular

[Q,R] = qr(A);

x = R (Q' * b);

end

For non-square matrices, QR decomposition is used. For square triangular matrices, it performs a simple forward/backward substitution. For square symmetric positive-definite matrices, Cholesky decomposition is used. Otherwise LU decomposition is used for general square matrices.

對於非方陣,使用QR分解。對於正方形三角形矩陣,它執行一個簡單的前向/向后替換。對於正方形對稱正定矩陣,使用Cholesky分解。對於一般的方陣,則采用LU分解。

Update: MathWorks has updated the algorithm section in the doc page of mldivide with some nice flow charts. See here and here (full and sparse cases).

更新:MathWorks已經在mlb的doc頁面中更新了算法部分,並提供了一些不錯的流程圖。看這里和這里(完整和稀疏的情況)。

ahr0chm6ly9plnn0ywnrlmltz3vylmnvbs9rvnn5ai5wbmc=

All of these algorithms have corresponding methods in LAPACK, and in fact it's probably what MATLAB is doing (note that recent versions of MATLAB ship with the optimized Intel MKL implementation).

所有這些算法在LAPACK中都有相應的方法,實際上,這可能是MATLAB所做的(注意,最近的MATLAB版本的ship使用了優化的Intel MKL實現)。

The reason for having different methods is that it tries to use the most specific algorithm to solve the system of equations that takes advantage of all the characteristics of the coefficient matrix (either because it would be faster or more numerically stable). So you could certainly use a general solver, but it wont be the most efficient.

使用不同方法的原因是,它嘗試使用最具體的算法來解決那些利用系數矩陣的所有特征的方程組(要么是因為它更快,要么更穩定)。所以你當然可以使用一個通用求解器,但它不會是最有效的。

In fact if you know what A is like beforehand, you could skip the extra testing process by calling linsolve and specifying the options directly.

事實上,如果您事先知道A是什么樣子,您可以通過調用linsolve和直接指定選項來跳過額外的測試過程。

if A is rectangular or singular, you could also use PINV to find a minimal norm least-squares solution (implemented using SVD decomposition):

如果A是矩形的或者是單數的,你也可以使用PINV來找到最小范數最小二乘解(用SVD分解實現):

x = pinv(A)*b

All of the above applies to dense matrices, sparse matrices are a whole different story. Usually iterative solvers are used in such cases. I believe MATLAB uses UMFPACK and other related libraries from the SuiteSpase package for direct solvers.

以上這些都適用於稠密矩陣,稀疏矩陣是一個完全不同的故事。通常在這種情況下使用迭代求解器。我相信MATLAB使用UMFPACK和其他相關的庫來直接求解。

When working with sparse matrices, you can turn on diagnostic information and see the tests performed and algorithms chosen using spparms:

當使用稀疏矩陣時,您可以打開診斷信息,並查看所執行的測試和使用spparms選擇的算法:

spparms('spumoni',2)

x = Ab;

What's more, the backslash operator also works on gpuArray's, in which case it relies on cuBLAS and MAGMA to execute on the GPU.

更重要的是,反斜杠運算符也適用於gpuArray,在這種情況下,它依賴於cuBLAS和岩漿在GPU上執行。

It is also implemented for distributed arrays which works in a distributed computing environment (work divided among a cluster of computers where each worker has only part of the array, possibly where the entire matrix cannot be stored in memory all at once). The underlying implementation is using ScaLAPACK.

它也適用於分布式計算環境(在一個計算機集群中,每個工作人員只有一個數組的一部分,可能整個矩陣不能同時存儲在內存中)。底層實現是使用ScaLAPACK。

That's a pretty tall order if you want to implement all of that yourself :)

如果你想自己實現所有這些,這是一個非常艱巨的任務

最后

以上就是温柔保温杯为你收集整理的matlab数据方块里面反斜杠,如何實現Matlab的mlb(即反斜杠運算符“\”)的全部内容,希望文章能够帮你解决matlab数据方块里面反斜杠,如何實現Matlab的mlb(即反斜杠運算符“\”)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(32)

评论列表共有 0 条评论

立即
投稿
返回
顶部