フィルターのクリア

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]

1 回表示 (過去 30 日間)
poppy
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]?

回答 (1 件)

Ishan
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!

カテゴリ

Help Center および File ExchangeDiscrete Math についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by