这是我的代码:
N=100;
n=50;
tau=0.001;
h=0.01;
lambda=tau/h;
mu=lambda/2;
u=zeros(N,n);
u1=zeros(N,n);
u2=zeros(N,n);
phi=zeros(n,1);
for i=1:n
for j=1:N
u(j,i)=cos(2*pi*i*(j-1)*h);
u1(j,i)=cos(2*pi*i*((j-1)*h-tau));
end
for j=2:N
u2(j,i)=u(j,i)-lambda*(u(j,i)-u(j-1,i));
end
u2(1)=0;
phi(i,1)=2*pi*i/N;
end
uf=zeros(n,1);
uf1=zeros(n,1);
uf2=zeros(n,1);
for i=1:n
for j=1:N
uf(i,1)=uf(i,1)+(u(j,i)*exp(-1i*(j-1)*phi(i,1)))/100;
uf1(i,1)=uf1(i,1)+u1(j,i)*exp(-1i*j*phi(i,1))/100;
uf2(i,1)=uf2(i,1)+(u2(j,i)*exp(-1i*(j-1)*phi(i,1)))/100;
end
end
final=zeros(n,1);
for i=1:n
final(i,1)=-(h/(1i*tau))*(log(uf2(i)/uf(i)));
end
figure;
hold on
z=1:1:n;
b = real(final(z,1));
%plot(phi(z,1),b,'o');
c = imag(final(z,1));
%plot(phi(z,1),c,'-');
%plot(phi(z,1),0,'-');
plot(phi(z,1),b,'ro',phi(z,1),c,'ko',phi(z,1),0,'k-');
legend('Real','Imaginary');
legend ('Location','NorthWest');
xlabel('Reduced Wavenumber')
ylabel('Modified Wavenumber')
我在 y=0 处绘制一条线以供参考。我不希望他们出现在传说中。但我得到了这个数字: 我该如何解决这个问题?