Gaussian Elimination script question

5 visualizaciones (últimos 30 días)
byungwan ko
byungwan ko el 23 de Nov. de 2019
Respondida: Dinesh Yadav el 26 de Nov. de 2019
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

Respuestas (1)

Dinesh Yadav
Dinesh Yadav el 26 de Nov. de 2019

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by