Finding the determinant without det(a)

22 ビュー (過去 30 日間)
Ryan Driver
Ryan Driver 2022 年 1 月 27 日
編集済み: DGM 2022 年 1 月 27 日
I need to physically computate the determinant of 3x3 matrices and lower without using the det(a) function, rather loops. What's causing this error?
  1 件のコメント
DGM
DGM 2022 年 1 月 27 日
編集済み: DGM 2022 年 1 月 27 日
Like Max, I'm guessing that matrix a1 isn't the expected size. In the future, it's best to post the code as formatted code instead of pictures so that people can troubleshoot it.
I'm just going to throw this out there. You can reuse the code for calculating the 2x2 case.
A = rand(3);
DA1 = det(A)
DA1 = 0.0476
DA2 = det33(A)
DA2 = 0.0476
function D = det22(A)
D = prod(A([1 4])) - prod(A([2 3]));
end
function D = det33(A)
D = A(1,1)*det22(A(2:3,2:3)) - A(1,2)*det22(A(2:3,[1 3])) + A(1,3)*det22(A(2:3,1:2));
end

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

採用された回答

Max Heimann
Max Heimann 2022 年 1 月 27 日
編集済み: Max Heimann 2022 年 1 月 27 日
According to the error you are trying to access an index which is not part of the variable.
Are you sure a1 is a 3x3 matrix?
It looks like you are calling the function with a 2x3 matrix [1 2 3; 4 5 6]
  1 件のコメント
Ryan Driver
Ryan Driver 2022 年 1 月 27 日
Stupid mistake. Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by