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
KALYAN ACHARJYA 2020년 12월 24일
편집: KALYAN ACHARJYA 2020년 12월 24일
What have you tried so far?
Elizabeth Brito
Elizabeth Brito 2020년 12월 24일
try to think of a way to replicate the formula they gave me but nothing turns out
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 24일
great keep it up, can you share the code?
C=[-2,3;6,5]
[m3,n3]=size(C)
z=zeros(m3,n3)
for i=det(C)
for j=transpose(C)
for k=
z(i,j)=
end
end
end
I have nothing else and I feel like I'm cheating and everything is wrong
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 24일
You can do that multiple ways. please refer here
Elizabeth Brito
Elizabeth Brito 2020년 12월 24일
thanks i will go check it
hi i checked that code but that is gauss method and i need cofactors method.
I made a new code but it doesn't work. Can you help me?
or how can i do it
C=[-2,3;
6,5]
[m,n]=size(C)
z=zeros(m,n)
%cofactor
c1= C(2,2)
c2 = -C(1,2)
c3 = -C(2,1)
c4 = C(1,1)
%matriz del cofactor
c = [c1,c3;
c2,c4]
for i=1:m %filas
for j=1:n %columnas
for k=transpose(c)
z(i,j)= (1/det(C(i,j)))*k
end
end
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Doddy Kastanya
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에 대해 자세히 알아보기

태그

질문:

2020년 12월 24일

답변:

2021년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by