We are asked to code our own dft function from the formula :

If everything is done correctly it should give the same result with matlab's own dft function, in the end I'm comparing them but they are not the same... We are not allowed to use for loops this is why Im trying to do it with matrices. Below is my code:
x=linspace(0,pi,10);
y=cos(x);
ones_vec = ones(10,1);
ones_vec=(ones_vec*y);
k=linspace(1,10,10);
n=linspace(0,9,10);
ones_vec_n = ones(10,1);
ones_vec_n = (ones_vec_n*n).';
ones_vec2 = ones(10,1);
ones_vec2=(ones_vec2*k*-1i*2*pi/10);
%n = n*ones_vec2.'
ones_vec2= ones_vec2 .* ones_vec_n;
dft_my = sum(ones_vec2,1)
fft_matlab = fft(y)
I would be glad if you can give a hand!
I checked the following in Octave: