# I can't find the error in this code. Please help with the dimension. Error in line 42

1 vue (au cours des 30 derniers jours)
Titas Chattopadhyay le 20 Déc 2021
clc
clear all
close all
%% Initial and Boundary conditions %%
g = 9.81;
J = 1.2./1000;
h = 0.075;
lambda = 0.075;
u_star = sqrt(g.*J.*h);
ny = 11; nz = 11; nt = 10; nit = 10;
%% Pressure term %%
P = (9.*u_star.^2)./h;
nu = 10^(-6)./(u_star.*h);
kappa = 0.4;
XXx = 0:0.1:1;
YYx = (XXx.*(1-XXx))./(1+12.*0.19.*XXx.^2.*(1-XXx));
FF = trapz(XXx,YYx);
nu_t = kappa.*FF;
%% Grids %%
dy = lambda./(ny-1);
dz = h./(nz-1);
dt = 0.01;
y = 0:0.1:1;
z = 0:0.1:1;
f = zeros(nz,ny);
g = zeros(nz,ny);
fn = zeros(nz,ny);
gn = zeros(nz,ny);
[Z,Y] = meshgrid(z,y);
%% Main calculation %%
fn = f; gn = g ; jeta = 1:nz-1; eta = 1:ny-1;
for i = 2:nz-1
for j = 2:ny-1
f(i,j) = ((dt.*g.*J) + fn(i+1,j+1))./(1 + dt.*(2.*pi.*1i.*jeta).*fn(i,j) + (4.*dt.*pi.^2).*((nu+nu_t).*(jeta.^2 + eta.^2)+(nu_t.*jeta.*eta)) + (dt.*nu_t.*2.*pi.*1i.*jeta.*gn(i+1,j+1))) ;
g(i,j) = ((dt.*g.*P) + gn(i+1,j+1))./(1 + dt.*(2.*pi.*1i.*eta).*gn(i,j) + (4.*dt.*pi.^2).*((nu+nu_t).*(jeta.^2 + eta.^2)+(nu_t.*jeta.*eta)) + (dt.*nu_t.*2.*pi.*1i.*eta.*fn(i+1,j+1))) ;
end
end
Arrays have incompatible sizes for this operation.
##### 2 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Titas Chattopadhyay le 20 Déc 2021

Connectez-vous pour commenter.

### Réponse acceptée

VBBV le 20 Déc 2021
clc
clear all
close all
%%Initial and Boundary conditions %%
g = 9.81;
J = 1.2./1000;
h = 0.075;
lambda = 0.075;
u_star = sqrt(g.*J.*h);
ny = 11; nz = 11; nt = 10; nit = 10;
%%Pressure term %%
P = (9.*u_star.^2)./h;
nu = 10^(-6)./(u_star.*h);
kappa = 0.4;
XXx = 0:0.1:1;
YYx = (XXx.*(1-XXx))./(1+12.*0.19.*XXx.^2.*(1-XXx));
FF = trapz(XXx,YYx);
nu_t = kappa.*FF
%%Grids %%
dy = lambda./(ny-1);
dz = h./(nz-1);
dt = 0.01;
y = 0:0.1:1;
z = 0:0.1:1;
f = zeros(nz,ny);
g = zeros(nz,ny);
fn = zeros(nz,ny);
gn = zeros(nz,ny);
[Z,Y] = meshgrid(z,y);
%%Main calculation %%
fn = f; gn = g ; jeta = 1:nz-1; eta = 1:ny-1;
for i = 2:nz-1
for j = 2:ny-1
f(i,j) = ((dt.*g(i,j).*J) + fn(i+1,j+1))./(1 + dt.*(2.*pi.*1i.*jeta(j)).*fn(i,j) + (4.*dt.*pi.^2).*((nu+nu_t).*(jeta(j).^2 + eta(j).^2)+(nu_t.*jeta(j).*eta(j))) + (dt.*nu_t.*2.*pi.*1i.*jeta(j).*gn(i+1,j+1))) ;
g(i,j) = ((dt.*g(i,j).*P) + gn(i+1,j+1))./(1 + dt.*(2.*pi.*1i.*eta(j)).*gn(i,j) + (4.*dt.*pi.^2).*((nu+nu_t).*(jeta(j).^2 + eta(j).^2)+(nu_t.*jeta(j).*eta(j))) + (dt.*nu_t.*2.*pi.*1i.*eta(j).*fn(i+1,j+1))) ;
end
end
Use the for loop indices where you have matrices /vectors Try the above
##### 1 commentaireAfficher AucuneMasquer Aucune
Titas Chattopadhyay le 21 Déc 2021

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by