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]
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Ishan
le 29 Nov 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Discrete Math dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!