Gaussian Elimination script question
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!