필터 지우기
필터 지우기

Gaussian Elimination script question

조회 수: 2 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by