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 次查看(过去 30 天)
显示 更早的评论
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 个)
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
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
Hope this helps you solve your problem!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Math 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!