フィルターのクリア

how do i use the in-built inv function to calculate a matrix inverse and then calculate A-1A and AA-1.

1 回表示 (過去 30 日間)
how do i use the in-built inv function to calculate a matrix inverse and then calculate A-1A and AA-1.
  1 件のコメント
Stephen23
Stephen23 2017 年 9 月 6 日
編集済み: Stephen23 2017 年 9 月 6 日
@David Craven: are you trying to solve some linear equations?
In general matrix inversion a very poor way of performing numeric calculations, and the inv documentation describes better ways of solving equations.

サインインしてコメントする。

採用された回答

Cam Salzberger
Cam Salzberger 2017 年 9 月 6 日
Hello David,
Strictly speaking, you would do it like this:
Ainv = inv(A);
Ainv*A
A*Ainv
However, as Stephen pointed out, there are faster and more accurate methods for calculating the inverse when you plan to solve linear equations or include it in some matrix algebra. These two commands are mathematically equivalent, but will be faster and more precise:
A\A % equivalent to Ainv*A
A/A % equivalent to A*Ainv
-Cam
  2 件のコメント
David Craven
David Craven 2017 年 9 月 6 日
編集済み: James Tursa 2017 年 9 月 6 日
I run this function
[Inverse,Result1,Result2] = matrixinverse(A)
Inverse = %calculate the inverse of a matrix with the inv function
Result1 = %calculate Inverse times A
Result2 = %calculate A times Inverse
Inverse = inv(A);
Result1 = A*Inverse;
Result2 = Inverse*A;
end
and get this
A =
9.6800 9.6100 2.2700
2.4100 5.3600 4.7900
9.7300 8.2000 9.2400
Error: File: matrixinverse.m Line: 2 Column: 70 Expression or statement is incomplete or incorrect.
Cam Salzberger
Cam Salzberger 2017 年 9 月 6 日
編集済み: Cam Salzberger 2017 年 9 月 6 日
Well, if line 2 of that file is:
Inverse = %calculate the inverse of a matrix with the inv function
then that looks incomplete to me. Maybe you should just remove those lines, and keep it to the other lines only.
-Cam

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2017 年 9 月 6 日
The comment character % needs to be at the beginning of the comments. So these lines
Inverse = %calculate the inverse of a matrix with the inv function
Result1 = %calculate Inverse times A
Result2 = %calculate A times Inverse
should be this instead
% Inverse = calculate the inverse of a matrix with the inv function
% Result1 = calculate Inverse times A
% Result2 = calculate A times Inverse

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by