如何避免“冲浪错误X,Y,Z和C不能复杂”

问题描述

我已经尝试更改xyz,但仍然无法正常工作。

错误表明存在问题

(第72行)surf(t / sigma,x * sqrt(P / sigma)/ sqrt(phi),abs(Y(:,1:M))));

我的完整代码是:

clc
M = input ('M = ');
N = input ('N = ');
epsilon = input ('epsilon = ');
dx = 0.01;
dt = 2.5000e-005;
x0 = -N/2*dx;
r = dt/dx^2;
D = 0.1*1.6e5;
mass=5.1e-13;
a=3e-2;
k=24;
K=8;
l=340;
lambda=10*1;
q=2*pi/lambda;
h=4;
sigma=1e10;
tau=0;
e2=0.001;
wg = 2*a*sqrt(D/mass);
w = sqrt(wg+(2*k*(1-cos(q*1))+2*K*(cos(q*l*h)+1))/mass);
Vg=(1*(k*sin(1*q)-K*h*sin(l*q*h))/(mass*w));
alfa = (-3*a)/sqrt(2);
beta = 7*a^2/3;
miu=-2*alfa/(1+4*K/ (mass*wg.^2));
delta=(wg.^2)*alfa/(4*w^2+2*k*(cos(2*q*1-1)/mass-2*K*(cos(2*h*q*l)+1)/mass-wg^2));
P=(((1^2)*(k*cos(1*q)-K*(h^2)*cos(l*q*h))/mass)-Vg^2)/(2*w);
Q=(-wg.^2*(2*alfa*(miu+delta)+3*beta)/(2*w));
phi= 0.0005;
psi=0.03;
F=zeros(N,M);
Y=zeros(N,M);
 for n=1:N
    x(n,1)=x0+(n-1)*dx;
    F(n,1)=((sqrt(2)/psi)*sech(x(n,1))/sqrt(phi));
  end

%running program
 for m=1:M
  for n=2:N-1
     if n==2
        F(n-1,m)=3*F(n,m)-3*F(n+1,m)+F(n+2,m);
     end
     if n==N-1
        F(n+1,m)-3*F(n-1,m)+F(n-2,m);
     end
    
     if m==1
        F(n,m+1)=1i*((phi^2*r*(F(n+1,m)-2*(F(n,m))+F(n-1,m))+(psi^2*dt*(conj(F(n,m))*(F(n,m)^2))+F(n,m))));
     else
        F(n,m+1)=2*1i*((phi^2*r*(F(n+1,m-1))));
     end
 t(m) = (m-1)*dt;
 theta(n,m)=(n*q*l)-(w*t(m)/e2);
 Y(n,m) = ((e2*(psi*F(n,m)/(sqrt(Q/sigma))))*(2*(cos((sigma*tau)+theta(n,m)))))+((e2^2*((psi*F(n,m)/(sqrt(Q/sigma)))^2))*(miu+(2*delta*(cos(2*((sigma*tau)+theta(n,m)))))));
 end

%grafik 3 dimensi
figure
surf(t/sigma,x*sqrt(P/sigma)/sqrt(phi),abs(Y(:,1:M)));
view(0,90);
colorbar
shading interp
xlabel ('T');
ylabel ('x');
zlabel ('y');

%grafik hubungan Y terhadap x
figure
plot((x*sqrt(P/sigma)),0)));
xlabel ('x(pm)');
ylabel ('Y(pm)');

figure
plot((x*sqrt(P/sigma)),M)));
xlabel ('x(pm)');
ylabel ('Y(pm)');

它使该图没有显示。请问我该怎么办?

解决方法

采用真实组件和MATLAB索引

为避免涉及虚构零件的错误,请添加real()函数以仅在绘制表面时使用真实零件:

surf(t/sigma,real(x*sqrt(P/sigma)/sqrt(phi)),abs(Y(:,1:M)));

MATLAB索引从“ 1”开始,而不是许多语言使用的“ 0”。将abs(Y(:,0))更改为abs(Y(:,1))可能是问题所在。

plot((real(x*sqrt(P/sigma))),1)));

添加其他end来关闭嵌套的for循环。

 for m=1:M
  for n=2:N-1
     if n==2
        F(n-1,m)=3*F(n,m)-3*F(n+1,m)+F(n+2,m);
     end
     if n==N-1
        F(n+1,m)-3*F(n-1,m)+F(n-2,m);
     end
    
     if m==1
        F(n,m+1)=1i*((phi^2*r*(F(n+1,m)-2*(F(n,m))+F(n-1,m))+(psi^2*dt*(conj(F(n,m))*(F(n,m)^2))+F(n,m))));
     else
        F(n,m+1)=2*1i*((phi^2*r*(F(n+1,m-1))));
     end
 t(m) = (m-1)*dt;
 theta(n,m)=(n*q*l)-(w*t(m)/e2);
 Y(n,m) = ((e2*(psi*F(n,m)/(sqrt(Q/sigma))))*(2*(cos((sigma*tau)+theta(n,m)))))+((e2^2*((psi*F(n,m)/(sqrt(Q/sigma)))^2))*(miu+(2*delta*(cos(2*((sigma*tau)+theta(n,m)))))));
 end
 end