Hello Community,
is it possible to write a code which is faster than my version?
function D = Dp(N)D = (zeros(N-1,N-1));for i=1:N-1 for j=1:N-1 if i ~= j D(i,j)= -.5 * sin(j*pi/N)^2/sin(i*pi/N)^2 *(-1)^(i+j)/(sin(pi*(i+j)/(2*N))*sin(pi*(i-j)/(2*N))); else D(i,j) = 3/2 * cos(pi*i/N)/sin(pi*i/N)^2; end endendend
the reference i should inplement is:
my "optimized" version:
function D = Dp(N)D = (zeros(N-1,N-1));for i=1:N-1 for j=1:N-1 if i ~= j D(i,j)= -.5 * sin(j*pi/N)^2/sin(i*pi/N)^2 *(-1)^(i+j)/(sin(pi*(i+j)/(2*N))*sin(pi*(i-j)/(2*N))); else end endendD = D + diag(1.5 * cos(pi*(1:N-1)/N)./sin(pi*(1:N-1)/N).^2);end
Best Answer