How to write cramer's rule 3x3 by matlab ?

조회 수: 129 (최근 30일)
ENG. Mohamed Ibrahim
ENG. Mohamed Ibrahim 2016년 3월 10일
편집: Sebastián 2025년 3월 12일
How to write cramer's rule 3x3 by matlab ?
  댓글 수: 1
James Tursa
James Tursa 2016년 3월 10일
What have you done so far? Do you know how to replace elements in a matrix with other elements? Do you know how to use a for loop? Do you know how to calculate the determinant of a matrix?

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

답변 (3개)

Explorer
Explorer 2016년 3월 10일
편집: Explorer 2016년 3월 10일
Question: Find the system of Linear Equations using Cramers Rule:
2x + y + z = 3
x – y – z = 0
x + 2y + z = 0
The above example is taken from http://www.purplemath.com/modules/cramers.htm
% Demo Code:
A = [2 1 1; 1 -1 -1; 1 2 1] % Coefficient Matrix
X = [3; 0; 0]
Ax = [3 1 1 ; 0 -1 -1;0 2 1 ]
Ay = [2 3 1; 1 0 -1; 1 0 1]
Az = [2 1 3; 1 -1 0; 1 2 0]
detA=det(A)
x = det(Ax)/detA
y = det(Ay)/detA
z = det(Az)/detA
  댓글 수: 6
James Tursa
James Tursa 2021년 1월 15일
Rather than creating the modified matrix with concatenation, a direct assignment of the column:
k = the column number to replace
mNAM = NAM;
mNAM(:,k) = I;
This could easily be put into a loop.
Sebastián
Sebastián 2025년 3월 12일
편집: Sebastián 2025년 3월 12일
This is my solution
%original matrix
x=[2 1 1;1 -1 -1;1 2 1]
res=[3 0 0]
detx=det(x)
sx=length(x)
ans=zeros(1,sx)
sistem=repmat(x,1,1,3);
%replace independent matrix in original matrix
for i=1:1:sx
sistem(:,i,i)=res;
ans(:,i)=det(sistem(:,:,i))/detx;
end
disp(ans)

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


Faith Ira Daro
Faith Ira Daro 2021년 11월 24일
given the linear equations:
3x+2y = -5
-5x+7y=1
solve for the values of x and y using cramers rule

Asif Iqbal
Asif Iqbal 2022년 1월 28일
% Demo Code:
A = [2 1 1; 1 -1 -1; 1 2 1] % Coefficient Matrix
X = [3; 0; 0]
Ax = [3 1 1 ; 0 -1 -1;0 2 1 ]
Ay = [2 3 1; 1 0 -1; 1 0 1]
Az = [2 1 3; 1 -1 0; 1 2 0]
detA=det(A)
x = det(Ax)/detA
y = det(Ay)/detA
z = det(Az)/detA

카테고리

Help CenterFile Exchange에서 Physical Units에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by