I have a problem with my code. My objective is to obtain the Fourier coefficients with the passage matrices. Then use the fft and check that my two results are the same. But I get different results and I don't understand why?
clear all;
N=[50];
for k=1:length(N)
Dx=1/(N(k)-1);
x=linspace(0,1-Dx,N(k));
for j=1:N(k)
f(j,k)=100.*exp(-20*x(j))*(x(j)-(x(j)).^2);
end
for j=1:N(k)
for m=1:N(k)
Mphsp(j,m)=exp((2*pi*i*(m-1)*(j-1))/N(k));
Mspph(j,m)=(1/N(k)).*exp(-(2*pi*i*(m-1)*(j-1))/N(k));
end
end
Idd=Mphsp*Mspph;
coeff(1:N(k),k)=Mspph*f(1:N(k),k);
coeff2(1:N(k),k)=fft(f(1:N(k),k));
verf(1:N(k),k)=coeff2(1:N(k),k)-coeff(1:N(k),k);
end
If anyone has any ideas? Please.
Your for loop is wrong. length(N) = 1, because N is a 1x1 matrix.
clear all;
N=[50];
for k=1:length(N)
I suppose you want to do something like
N = zeros(50, 1);
for k = 1:50
N(k) = k;
end
for k=1:length(N)
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.