# How can I make a guess sidel function with the given variables: GS(Am,bm,iโnitial_gueโss,10^-4) and the range is ๐ = [20, 40, 80, 160, 320, 640, 1280]

์กฐํ ์: 3(์ต๊ทผ 30์ผ)
poppy 2022๋ 11์ 27์ผ
๋ต๋ณ: Ishan 2022๋ 11์ 29์ผ
How can I make a guess sidel function with the given variables: GS(Am,bm,initial_guess,10^-4) and the range is ๐ = [20, 40, 80, 160, 320, 640, 1280]?
##### ๋๊ธ ์: 0ํ์์จ๊ธฐ๊ธฐ ์ด์  ๋๊ธ ์: -1

๋๊ธ์ ๋ฌ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ญ์์ค.

### ๋ต๋ณ(1๊ฐ)

Ishan 2022๋ 11์ 29์ผ
Hi Anujan,
If you want to solve a linear equation by Gauss-Seidel method, you can use the below function to do so:
%A = input('Enter a Co-effecient Matrix A: ');
A = [10 3 1;3 10 2;1 2 10];
%B = input('Enter Source Vector B: ');
B = [19;29;35];
%P = input('Enter initial Guess Vector: ');
P = [0;0;0];
%n = input('Enter no. of iterations: ');
n = 10;
%e = input('Enter your tollerance: ');
e = 0.0001
e = 1.0000e-04
N = length(B);
X = zeros(N,1);
Y = zeros(N,1);
for j=1:n
for i = 1:N
X(i) = (B(i)/A(i,i))-(A(i,[1:i-1,i+1:N])*P([1:i-1,i+1:N]))/A(i,i);
P(i) = X(i);
end
fprintf('Iteration no. %d\n', j)
X
if abs(Y-X)<e
break
end
Y=X;
end
Iteration no. 1
X = 3ร1
1.9000 2.3300 2.8440
Iteration no. 2
X = 3ร1
0.9166 2.0562 2.9971
Iteration no. 3
X = 3ร1
0.9834 2.0056 3.0005
Iteration no. 4
X = 3ร1
0.9983 2.0004 3.0001
Iteration no. 5
X = 3ร1
0.9999 2.0000 3.0000
Iteration no. 6
X = 3ร1
1.0000 2.0000 3.0000
Iteration no. 7
X = 3ร1
1.0000 2.0000 3.0000
Hope this helps you solve your problem!
##### ๋๊ธ ์: 0ํ์์จ๊ธฐ๊ธฐ ์ด์  ๋๊ธ ์: -1

๋๊ธ์ ๋ฌ๋ ค๋ฉด ๋ก๊ทธ์ธํ์ญ์์ค.

### ๋ฒ์ฃผ

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by