Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

mldivide, \

x に対する線形方程式 Ax = B の求解

説明

x = A\B は線形方程式系 A*x = B を解きます。行列 A と行列 B の行数は同じでなければなりません。MATLAB® は、A のスケールが不適当またはほぼ特異値の場合は警告メッセージを表示しますが、計算は関係なく実行します。

  • A がスカラーの場合、A\BA.\B と等価です。

  • Ann 列の正方行列、Bn 行の行列である場合、x = A\B は存在する場合は方程式 A*x = B の解となります。

  • Am ~= n である mn 列の方形行列で、Bm 行の行列の場合、A\B は方程式系 A*x= B の最小二乗解を返します。

x = mldivide(A,B)x = A\B の代替方法として実行できますが、まれにしか使用されません。これにより、クラスの演算子のオーバーロードが可能です。

すべて折りたたむ

単純な線形方程式 A*x = B を解きます。

A = magic(3);
B = [15; 15; 15];
x = A\B
x = 3×1

    1.0000
    1.0000
    1.0000

特異行列 A を含む線形方程式系 A*x = b を解きます。

A = magic(4);
b = [34; 34; 34; 34];
x = A\b
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.306145e-17.
x = 4×1

    1.5000
    2.5000
   -0.5000
    0.5000

rcond0eps の間にある場合、特異行列に近いことを示す警告が MATLAB® によって表示されますが、計算は続行されます。悪条件の行列を扱う場合、残差 (b-A*x) が比較的小さい値であっても信頼できない解となる可能性があります。この例では、rcond が小さい値であっても、残差のノルムは 0 であり、厳密解が得られます。

rcond0 に等しい場合、特異値の警告が表示されます。

A = [1 0; 0 0];
b = [1; 1];
x = A\b
Warning: Matrix is singular to working precision.
x = 2×1

     1
   Inf

この場合、ゼロ除算により InfNaN の計算が発生し、計算結果が信頼できないものになります。

線形方程式系 A*x = b を解きます。

A = [1 2 0; 0 4 3];
b = [8; 18];
x = A\b
x = 3×1

         0
    4.0000
    0.6667

スパース行列を使って単純な線形方程式を解きます。

以下の行列方程式 A*x = B を考えます。

A = sparse([0 2 0 1 0; 4 -1 -1 0 0; 0 0 0 3 -6; -2 0 0 0 2; 0 0 4 2 0]);
B = sparse([8; -1; -18; 8; 20]);
x = A\B
x = 
   (1,1)       1.0000
   (2,1)       2.0000
   (3,1)       3.0000
   (4,1)       4.0000
   (5,1)       5.0000

入力引数

すべて折りたたむ

オペランド。ベクトル、非スパース行列またはスパース行列として指定します。AB の行数は同じでなければなりません。

  • A または B の一方が整数データ型をもつ場合、もう一方の入力はスカラーでなければなりません。整数データ型のオペランドは、複素数にできません。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char
複素数のサポート: あり

出力引数

すべて折りたたむ

ベクトル、非スパース行列またはスパース行列として返される解。Amn 列の行列で Bmp 列の行列の場合、x は、np 列の行列になります。これは p==1 の場合を含みます。

A が非スパース ストレージの場合、x も非スパースになります。A がスパース行列の場合、xB と同じストレージをもちます。

ヒント

  • 演算子 / と演算子 \ は、方程式 B/A = (A'\B')' によって相互に関連しています。

  • A が正方行列の場合には、A\Binv(A)*B におおよそ等しくなりますが、MATLAB は別の方法でより確実に A\B を処理します。

  • A のランクが A の列数よりも小さい場合、x = A\B は最小ノルム解であるとは限りません。最小ノルムの最小二乗解は、x = lsqminnorm(A,B) または x = pinv(A)*B を使用して計算できます。

  • 線形システムを異なる右辺について効率的に複数回解くには、decomposition オブジェクトを使用します。decomposition オブジェクトは繰り返して解を求める必要のある問題に適しています。これは、係数行列の分解を複数回実行する必要がないためです。

アルゴリズム

すべて折りたたむ

mldivide が線形システムを解く際の多様性は、適切なソルバーにディスパッチすることで問題の対称性を利用する能力に起因します。この方法は、計算時間を最小限に抑えることを目的としています。関数は、最初に "非スパース" ("密" とも呼ばれる) 入力配列と、"スパース" 入力配列との差異を区別します。

非スパース入力のアルゴリズム

以下のフローチャートは、入力 AB非スパースの場合のアルゴリズム パスを示します。

The properties of full input matrices determine which algorithm mldivide uses to solve the linear system

スパース入力のアルゴリズム

A が非スパースで B がスパースの場合、mldivideB を非スパース行列に変換し、非スパース アルゴリズム パス (上記) を使用して非スパース ストレージの解を計算します。A がスパースの場合は、以下に示すように、解 x のストレージは B のストレージと同じになり、mldivideスパース入力のアルゴリズム パスをたどります。

The properties of sparse input matrices determine which algorithm mldivide uses to solve the linear system

参照

[1] Gilbert, John R., and Tim Peierls. “Sparse Partial Pivoting in Time Proportional to Arithmetic Operations.” SIAM Journal on Scientific and Statistical Computing 9, no. 5 (September 1988): 862–874. https://doi.org/10.1137/0909058.

[2] Anderson, E., ed. LAPACK Users’ Guide. 3rd ed. Software, Environments, Tools. Philadelphia: Society for Industrial and Applied Mathematics, 1999. https://doi.org/10.1137/1.9780898719604.

[3] Davis, Timothy A. "Algorithm 832: UMFPACK V4.3 – an unsymmetric-pattern multifrontal method." ACM Transactions on Mathematical Software 30, no. 2 (June 2004): 196–199. https://doi.org/10.1145/992200.992206.

[4] Duff, Iain S. “MA57---a Code for the Solution of Sparse Symmetric Definite and Indefinite Systems.” ACM Transactions on Mathematical Software 30, no. 2 (June 2004): 118–144. https://doi.org/10.1145/992200.992202.

[5] Davis, Timothy A., John R. Gilbert, Stefan I. Larimore, and Esmond G. Ng. “Algorithm 836: COLAMD, a Column Approximate Minimum Degree Ordering Algorithm.” ACM Transactions on Mathematical Software 30, no. 3 (September 2004): 377–380. https://doi.org/10.1145/1024074.1024080.

[6] Amestoy, Patrick R., Timothy A. Davis, and Iain S. Duff. “Algorithm 837: AMD, an Approximate Minimum Degree Ordering Algorithm.” ACM Transactions on Mathematical Software 30, no. 3 (September 2004): 381–388. https://doi.org/10.1145/1024074.1024081.

[7] Chen, Yanqing, Timothy A. Davis, William W. Hager, and Sivasankaran Rajamanickam. “Algorithm 887: CHOLMOD, Supernodal Sparse Cholesky Factorization and Update/Downdate.” ACM Transactions on Mathematical Software 35, no. 3 (October 2008): 1–14. https://doi.org/10.1145/1391989.1391995.

[8] Davis, Timothy A. “Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing Sparse QR Factorization.” ACM Transactions on Mathematical Software 38, no. 1 (November 2011): 1–22. https://doi.org/10.1145/2049662.2049670.

拡張機能

バージョン履歴

R2006a より前に導入

すべて展開する