Skip to content

Instantly share code, notes, and snippets.

@soldev-42
Created November 3, 2015 18:10
Show Gist options
  • Select an option

  • Save soldev-42/cf3cae83aae7dde53b2e to your computer and use it in GitHub Desktop.

Select an option

Save soldev-42/cf3cae83aae7dde53b2e to your computer and use it in GitHub Desktop.
function [value] = gauss_seidel(A, b, x0, n)
rozmiar = size(A,1);
suma1 = 0;
suma2 = 0;
r = x0; //kolejne przyblizenia
for k=1 : n //wykonaj n krokow metody
for w=1 : rozmiar //kolejne wspolrzedne rozwiazania w k-tym kroku metody
//wykorzystuje 'stare' r
for j=(w+1) : rozmiar
suma1 = suma1 + (A(w,j) * r(j,1));
end
//wykorzystuje 'nowe' r
for j=1:w-1
suma2 = suma2 + (A(w,j) * r(j,1));
end
r(w,1)=(A(w,w)^(-1))*(b(w,1)-suma1-suma2);
suma1 = 0;
suma2 = 0;
end;
end;
value=r;
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment