Cramer's Rule using for loop

23 ビュー (過去 30 日間)
Matthias Bossenbroek
Matthias Bossenbroek 2018 年 10 月 1 日
コメント済み: Rakib Seemanto 2020 年 11 月 1 日
Hi,
For a school exercise I need to use Cramer's rule to determine Ax=b.
I need to execute this using a for loop. Currently I'm facing an issue where if I replace the column's off A by, they will remain b so that my next determinant (x2) is not correct. How do I get the original (a1) column back in the second loop, (and again for the third en fourth)?
my current code:
A = [1,1,-3,2;0,-1,4,0;-3,1,2,2;1,2,3,6]
b = [1;2;3;4]
detA = det(A)
[z,z] = size(A);
for g = 1:z;
A(:,g) = b
x = det(A)
end
Cheers,
Matthias
  4 件のコメント
Anusha Sridharan
Anusha Sridharan 2019 年 1 月 9 日
[Answers Dev] Restored Edits
Rakib Seemanto
Rakib Seemanto 2020 年 11 月 1 日
how to find the value of x and y by using Cramer’s rule from these equations:
𝑎𝑥+𝑏𝑦=𝑐 and 𝑑𝑥+𝑒𝑦=𝑓 ???

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

採用された回答

KSSV
KSSV 2018 年 10 月 3 日
編集済み: KSSV 2018 年 10 月 3 日
A = rand(3) ;
b = rand(3,1) ;
[m,n] = size(A) ;
x = zeros(m,1) ;
for i = 1:m
T = A ;
T(:,i) = b ;
x(i) = det(T)/det(A) ;
end
% Simply use \
sol = A\b ;
[x sol]
  1 件のコメント
Rakib Seemanto
Rakib Seemanto 2020 年 11 月 1 日
how to find the value of x and y by using Cramer’s rule from these equations:
𝑎𝑥+𝑏𝑦=𝑐 and 𝑑𝑥+𝑒𝑦=𝑓 ???

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by