Determinant and Inverse problem
11 ビュー (過去 30 日間)
古いコメントを表示
I need help with the following; a function takes a generic 2×2 matrix as input, and returns two outputs: the determinant and the inverse. Also, if the determinant is zero, the inverse is set to be an empty matrix (value []), or if the determinant is non-zero, then it calculates the inverse. This needs to be done without using det() and inv() functions. Thank you for your time.
7 件のコメント
Geoff Hayes
2015 年 11 月 1 日
Ben - a link for the algorithm in finding the inverse of a 2x2 matrix was posted in @Johannes' comment. Look at the Shortcut for 2x2 matrices and you should be able to figure out what is missing. (You have the determinant, so half the work is complete.)
回答 (1 件)
Jan
2015 年 11 月 1 日
編集済み: Jan
2015 年 11 月 1 日
You want to determine the inverse of a 2x2 matrix. So write down the definition paper:
[a, b; c, d] * [ai, bi; ci, di] = [1, 0; 0, 1]
This can be written as 4 equations with 4 unknowns and you can solve this manually. You get e.g.:
inv_A(2,2) = -A(1,2) / (A(1,1) * A(2,2) - A(1,2) * A(2,1))
Perhaps you recognize some parts of this expression?
6 件のコメント
Geoff Hayes
2015 年 11 月 1 日
Ben - I don't understand the diagonal code in your 2x2 matrix inverse function which is still hard-coded as
DiagonalA2by2 = [7 -3; -8 2];
Again, look at the link posted by @Johannes in his comment. It will tell you exactly how to invert a 2x2 matrix that has the form of
A = [a b
c d]
where a, b, c, and d are real numbers. Start with that before proceeding to the 3x3 case (which your code still overwrites the input matrix with A3by3 = [1 2 3; 0 4 5; 1 0 6]).
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!