I'm not sure if this question is entirely on-topic here, please notify if not. I feel it is more a math related problem, than a programming problem.
Following the advice in this answer I'm trying to implement the Extended Euclidean Algorithm. The linked answer as well as one of the standard sources:
McEliece, Robert J.; Shearer, James B., A property of Euclid’s algorithm and an application to Padé approximation, SIAM J. Appl. Math. 34, 611-615 (1978). ZBL0384.10006.
yield the same results, when I implement them. However, my results do not match the example given in McEliece and I have a hard time figuring out what I'm doing wrong.
My Code: using Matlab's quorem function:
syms a b x r t q s
a = x^7;
b = -x^6 + x^5 - x^3 + x^2 + x + 1;
s(-1+2) = 1;
t(-1+2) = 0;
r(-1+2) = a;
s(0+2) = 0;
t(0+2) = 1;
r(0+2) = b;
for k = 1:4
[q(k+2), r(k+2)] = quorem(r(k-2+2),r(k-1+2),x);
s(k+2) = s(k-2+2) - q(k+2)*s(k-1+2);
t(k+2) = t(k-2+2) - q(k+2)*t(k-1+2);
end
disp( [ (1:5).'-2 r(:), q(:) ] )
(the +2 just shifts the index to a valid range)
yields to for $r_i$ and $q_i$:
[ -1, x^7, q]
[ 0, - x^6 + x^5 - x^3 + x^2 + x + 1, 0]
[ 1, x^5 - x^4 + 2*x^2 + 2*x + 1, - x - 1]
[ 2, x^3 + 3*x^2 + 2*x + 1, -x]
[ 3, - 21*x^2 - 14*x - 9, x^2 - 4*x + 10]
[ 4, x/63, - x/21 - 1/9]
[ 5, 0, 0]
Which is similar, but starting with line 3, not the same. I checked the code a dozen times, what am I doing wrong?


