Inverse matrix with for loop
古いコメントを表示
Using for loops, program a general code for calculating the inverse of a given matrix in the 2X2 and 3X3 cases.
Can someone help me? I'm learning to use the for loop and I don't know how to do that.
7 件のコメント
KALYAN ACHARJYA
2020 年 12 月 24 日
編集済み: KALYAN ACHARJYA
2020 年 12 月 24 日
What have you tried so far?
Elizabeth Brito
2020 年 12 月 24 日
KALYAN ACHARJYA
2020 年 12 月 24 日
great keep it up, can you share the code?
Elizabeth Brito
2020 年 12 月 24 日
KALYAN ACHARJYA
2020 年 12 月 24 日
You can do that multiple ways. please refer here
Elizabeth Brito
2020 年 12 月 24 日
Elizabeth Brito
2020 年 12 月 24 日
回答 (1 件)
Doddy Kastanya
2021 年 1 月 6 日
0 投票
The way you prepare the cofactor is okay. You want to define your "k=transpose(c)" outside of the loop. The other thing that you need to remember is the intrinsic function "det" is to determine the determinant of a matrix. Applying it on an element of a matrix will just give you the element back. So, your code should look something like:
c=[c1, c3;c2, c4];
k=transpose(c); % or you could simply use k=c';
denum=det(C);
for i=1:m
for j=1:n
z(i,j)=1/denum*k(i,j);
end
end
The same principal is applicable for a 3x3 matrix. You just need to be careful in defining the cofactors (including the "+" and "-" signs). Good luck.
カテゴリ
ヘルプ センター および 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!