0

下面的编码是为了解决与热模型解耦的连续性方程我需要根据编码生成冰厚度的 3D 图 h_t=B+(D h_x)_x D=Gam |h_x|^(n-1) h^(n +2)

n=3;
L=750000; % meters
dtyear=10;
Nx=30;
type=1;
Mt=ceil(25000/dtyear);
dx=(2*L)/Nx; x=-L:dx:L; % x grid
xmid=-L+dx/2:dx:L-dx/2; % midpt grid
xplot=linspace(-L,L,400); % for plotting analytical soln
iceconstants; %Gam=2*(rho*g)^n*A;
% constants related to grid
dt=dtyear*SperA;
R0=dt/(dx*dx); % presumed related to stability for continuity eqn
Tend=dt*Mt; % final time
t=0:dt:Tend;
% use either steady state analytical soln or zero as initial condition
ic=hexact;
%ic=zeros(1,Nx+1);
% allocate space for solutions
hh=zeros(Nx+1,Mt+1); % hh(j,l) with j for x and l for t
D=zeros(Nx+1,1); %column vector
hh(:,1)=ic'; %insert initial condition
%enforce boundary conditions at start
hh(1,:)=0; hh(Nx+1,:)=0;
D(1)=0; D(Nx+1)=0; % see steady bdry

for l=1:Mt
delh=(hh(2:Nx+1,l)-hh(1:Nx,l))/dx; % Nx by 1 column vector
hav=(hh(2:Nx+1,l)+hh(1:Nx,l))/2; % Nx by 1 col vect
Dmid=(Gam/(n+2))*hav.^(n+2).*abs(delh).^(n-1); % Nx by 1 col vect
F=Dmid.*(hh(2:Nx+1,l)-hh(1:Nx,l));
hh(2:Nx,l+1)=hh(2:Nx,l)+B*dt+R0*(F(2:Nx)-F(1:Nx-1));
end;

tplot=t(tt);
hplot=hh(:,tt);
subplot(3,1,3), mesh(tplot/SperA,x/1000,hplot), view(37.5,30); <--problem in this line

当我运行这个编码时,我得到了这个结果

the result shows like this : 

??? Error using ==> mesh at 80
Data dimensions must agree.

Error in ==> iceA at 144
subplot(3,1,3), mesh(tplot/SperA,x/1000,hplot), view(37.5,30);

“数据维度必须一致”是什么意思?如果你能帮助我,我真的很感激:

4

1 回答 1

0

错误意味着tplot,xhplot应该具有相同的维度,即size()所有三个的输出应该相同。

如果它们是彼此独立生成的,请注意使网格点的大小与网格值的大小相同,即在矩阵中进行二次采样或索引时。

X在分析形成函数时,如下所示,如果和Y具有不同的大小,MATLAB 将抛出错误。如果不是,将具有与网格点矩阵和Z相同的输出大小。XY

[X,Y] = meshgrid(-5:1:5);
Z = X.^2 + Y.^2;
mesh(X,Y,Z);
于 2013-03-16T04:36:59.667 回答