Skip to content

Commit

Permalink
Gauss seidel method has been updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mhRumi committed Nov 18, 2019
1 parent 0f8af55 commit e26b27d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
A = [4,1,2,-1; 3,6,-1,2; 2,-1,5,-3; 4,1,-3,-8];
B = [2; -1; 3; 2];
n = length(B);
x = zeros(n,1);
x(:) = 0;

for it = 1:100
conv = true;
for i = 1 : n
function retval = Seidel(A, b)
[r c] = size(A);
b = b';
n = length(b);
x = zeros(n, 1);

for iteration = 1:20
for i = 1:n
sum = 0;
for j = 1 : n
if j ~= i
sum += A(i, j)*x(j);
end
end
temp = x(i);
x(i) = -1 * (sum - B(i)) / A(i,i);
if abs(temp - x(i)) > 1e-6
conv = false;
end
end;
if conv
break
end
end

disp("Solution: ")
x
disp("Iteration: ")
it
for j = 1:n
if i ~= j
sum = sum + A(i, j)*x(j);
endif
endfor
x(i) = -1/A(i, i) * (sum - b(i));
endfor
endfor
retval = [x'];
endfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Gauss jacobi Method
###### Author: [Mehedi Hasan Rumi](https://github.com/mhRumi)

This comment has been minimized.

Copy link
@RakibulRanak

RakibulRanak Nov 18, 2019

Contributor

Nam vallage nai


#### Function Arguments
* **A**: Coefficient matrix of linear equarions (Size: m x m)
* **b**: Constants matrix of equations (Size: m x 1)

*Here **m** is the number of equations in the input*

#### Function Returns
* Solution matrix

0 comments on commit e26b27d

Please sign in to comment.