MATLAB: Question about DFT and FFT comparision

comparisiondftfftMATLABscaling factor

I am interested about FFT scaling in MATLAB, so I have studied discussion in https://www.mathworks.com/matlabcentral/answers/15770-scaling-the-fft-and-the-ifft and basing on the informations desribed there I wanted to compare the results obtained from FFT and hand-written DFT algorithm. Here is the code:
% DFT
fs=5; % Sampling Frequency
t=0:1/fs:7/fs; % Time vector with the length of 8 (2^3)
A=0.5;
s=A*sin(2*pi*2*t);
S=zeros(length(s));
L=length(s);
for m=1:L
for n=1:L
S(n,m)=s(1,m)*exp(-2*pi*1i*(m*n)/L); % DFT from the formula
end
end
S2=zeros(1,L);
for k=1:L
S2(k) = sum(S(k,:));
end
S2_mag =abs(S2)/fs % Magnitude response scaled by the 1/fs factor
Then, I've prepared code for FFT:
N=2^nextpow2(L);
S1=fft(s,N);
Sm=abs(S1)/fs
At the end I've compared vectors S2_mag and Sm, here are the results:
>> Sm
Sm =
0.0363 0.0407 0.0629 0.3632 0.1539 0.3632 0.0629 0.0407
>> S2_mag
S2_mag =
0.0407 0.0629 0.3632 0.1539 0.3632 0.0629 0.0407 0.0363
I've noticed that I didn't have to multiply the DFT result by the L*A/2 (although in the link I've attached there stands that FFT implementation is scaled by this factor), while I've noticed that the result of DFT is the same as FFT, but it is "shifted" somewhat, so the second element of Sm is equal to the first in S2_mag and so on. I'm a little bit confused. Does anybody know the reason of this result?

Best Answer

https://in.mathworks.com/help/signal/ug/discrete-fourier-transform.html
https://in.mathworks.com/help/matlab/ref/fft.html