注:私は両方のMATLABとC#の次の例の最終結果を比較すると、この問題はmy previous question here on Matrix right division行列乗算誤差
に関連して、私は顕著があることに気付きます差。なぜこれはそうですか?
行列の逆行列を求めた結果が集計されているように見えますが、A * A^-1は途切れているようです。 MATLABで
例:C#で
>> a = [1 2 3; 4 5 6; 7 8 10]
a =
1 2 3
4 5 6
7 8 10
>> inv(a)
ans =
-0.6667 -1.3333 1.0000
-0.6667 3.6667 -2.0000
1.0000 -2.0000 1.0000
>> z = mtimes(a, inv(a))
>> z
z =
1.0000e+00 -4.4409e-16 -1.1102e-16
1.3323e-15 1.0000e+00 -2.2204e-16
2.2204e-15 -2.6645e-15 1.0000e+00
同じデータ: using CSML Matrix Library
//using CSML Matrix Library
public static Matrix operator *(Matrix A, Matrix B)
{
if (A.ColumnCount != B.RowCount)
throw new ArgumentException("Inner matrix dimensions must agree.");
Matrix C = new Matrix(A.RowCount, B.ColumnCount);
for (int i = 1; i <= A.RowCount; i++)
{
for (int j = 1; j <= B.ColumnCount; j++)
{
C[i, j] = Dot(A.Row(i), B.Column(j));
}
}
return C;
}
Console.WriteLine(e1);
1; 2; 3; \
4; 5; 6; \
7; 8; 10; \
Console.WriteLine(e1.Inverse());
-0.666666666666667; -1.33333333333333; 1; \
-0.666666666666669; 3.66666666666667; -2; \
1; -2; 1; \
Console.WriteLine(e1 * e1.Inverse());
0.999999999999999; 1.77635683940025E-15; -8.88178419700125E-16; \
-5.32907051820075E-15; 1.00000000000001; -3.5527136788005E-15; \
-1.06581410364015E-14; 3.5527136788005E-15; 0.999999999999996; \
違いは非常に小さいようです。機械の精度の順番では、 'eps(1)'です。たとえインバースアルゴリズムが同じように実装されたとしても、あなたはまだ完全に異なる2つの言語/コンパイラを使用しており、浮動小数点で作業するときはそのような違いがあるはずです。 – horchler