Effacer les filtres
Effacer les filtres

Gaussian Elimination script question

2 vues (au cours des 30 derniers jours)
byungwan ko
byungwan ko le 23 Nov 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

Réponses (1)

Dinesh Yadav
Dinesh Yadav le 26 Nov 2019

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by