Gaussian Elimination script question

3 ビュー (過去 30 日間)
byungwan ko
byungwan ko 2019 年 11 月 23 日
回答済み: Dinesh Yadav 2019 年 11 月 26 日
Hi, I want to solve Ax = b. A is mxn and b is nx1. Thus x is nx1.
I want to print two answers (which satisfies Ax = 0 and Ax = b)
but i couldn't proceed further than this one. in line 8, if i have 0 in A(k,k), i need to swap k th row with another row (bigger than k) or make pivot in other column but I couldn't do it.
for example, if A is [1,3,3,2;2,6,9,5;-1,-3,3,0] and b is [1;5;5],
[1,3,3,2;2,6,9,5;-1,-3,3,0] becomes [1,3,3,2;0,0,3,1;0,0,0,0] after one procedure. I need help please : )
function x = gaussianelim(A,b)
[row,col]=size(A);
m = row;
n = col;
x = zeros(m,1);
for k=1:m-1
for i=k+1:m
mul = A(i,k)/A(k,k);
for j=k+1:n
A(i,j) = A(i,j)-mul*A(k,j);
end
b(i) = b(i)-mul*b(k);
end
end

回答 (1 件)

Dinesh Yadav
Dinesh Yadav 2019 年 11 月 26 日

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by