Traduction code en python

Bonjour,

Je souhaiterais transposer le code que j'ai actuellement en code python, cependant j'ai des problèmes d'index. Si quelqu'un pouvait me donner un petit coup de main, ça serait bien sympathique

Code original :

function x=GS(A,y,xo,itmax)
%
n = length(y);
x = xo;
for it=1:itmax
for i=1:n
x(i)=(y(i)-A(i,1:i-1)*x(1:i-1)-A(i,i+1:n)*x(i+1:n))/A(i,i);
end
end

1 réponse

  1. Salut :
    def x(A,y,xo,itmax):
    n = length(y);
    x = xo;
    for it in range(1, itmax):
    for i in range(1, n):
    x(y(i)-A(i,1:i-1)*x(1:i-1)-A(i,i+1:n)*x(i+1:n))/A(i,i));

    c'est pas sure