-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gauss seidel method has been updated
- Loading branch information
mhRumi
committed
Nov 18, 2019
1 parent
0f8af55
commit e26b27d
Showing
2 changed files
with
29 additions
and
28 deletions.
There are no files selected for viewing
46 changes: 18 additions & 28 deletions
46
NumericalAnalysis/SystemOfLinearEquations/GaussSeidelMethod/Octave/GaussSeidel.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
NumericalAnalysis/SystemOfLinearEquations/GaussSeidelMethod/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
|
||
#### 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 |
Nam vallage nai