I was trying to compute a matrix of values using the following codes (simplified):
n = 5;xk = zeros(n+1);for i = 0:n Tempprod = 1; for j = 0:n xk(i+1,j+1) = cos(pi*(2j+1)/(2*(n+1))); endend
The output of the above code is
xk = 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i 1.1014 - 0.1418i
However, if I tried to compute one single value, say , I tried
cos(pi*(2*1+1)/(2*(5+1)))
and Matlab gave me the answer:
ans = 0.7071
So what I went wrong in the codes before? How can I fix it?
Best Answer