필터 지우기
필터 지우기

i got this error "Index exceeds the number of array elements (1)." at the first line starting " U(j, n + 1, dt_index)" when the first loop completed for one time

조회 수: 1 (최근 30일)
i am trying to solve coutte flow problem using dufort-frankel Finite difference method and i got this error "Index exceeds the number of array elements (1)." at the first line starting " U(j, n + 1, dt_index)" when the first loop completed for one time .
why it's happen and how to solve ?
Defining Variables
clc,clear;
v = 0.000217; % Kinematic Viscosity
h = 0.04; dy = 0.001; % Y Dimension
Ny = length(linspace(h,0,round(h/dy))) ;
% Ny = 5 ;
dt_values = [0.002, 0.003]; % Time Dimension
Nt_values = [541, 361];
% Initial Condition
ic = 0;
% Boundary Conditions
BC_Top = 0;
BC_Bottom = 40;
for dt_index = 1:length(dt_values)
dt = dt_values(dt_index);
Nt = Nt_values(dt_index);
% Diffusion Number
d = (v * dt) / (dy^2);
% Defining Domain
U = zeros(Ny + 1, Nt, length(dt_values));
% Initial Condition
U(:, 1, :) = ic;
% Boundary Conditions
U(1, :, :) = BC_Top;
U(end, :, :) = BC_Bottom;
% Solution
for k = 1:length(dt_values)
for n = 1:Nt - 1
if n == 1
for j = 2:Ny
U(j, n + 1, dt_index) = U(j, n, dt_index) + d(dt_index) * (U(j + 1, n, dt_index) - 2 * U(j, n, dt_index) + U(j - 1, n, dt_index));
end
else
for j = 2:Ny
U(j, n + 1, dt_index) = (U(j, n - 1, dt_index) + 2 * d(dt_index) * (U(j + 1, n, dt_index) - U(j, n - 1, dt_index) + U(j - 1, n, dt_index))) / (1 + 2 * d(dt_index));
end
end
end
end
end
Index exceeds the number of array elements. Index must not exceed 1.

채택된 답변

Walter Roberson
Walter Roberson 2023년 12월 6일
for dt_index = 1:length(dt_values)
dt = dt_values(dt_index);
Nt = Nt_values(dt_index);
You extract particular scalars from dt_values and Nt_values, getting scalar dt and Nt
d = (v * dt) / (dy^2);
and use them to calculate scalar d
U(j, n + 1, dt_index) = U(j, n, dt_index) + d(dt_index) * (U(j + 1, n, dt_index) - 2 * U(j, n, dt_index) + U(j - 1, n, dt_index));
and
U(j, n + 1, dt_index) = (U(j, n - 1, dt_index) + 2 * d(dt_index) * (U(j + 1, n, dt_index) - U(j, n - 1, dt_index) + U(j - 1, n, dt_index))) / (1 + 2 * d(dt_index));
in both of those statements you have d(dt_index) -- but d is scalar and so should not be indexed at d_index

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Boundary Conditions에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by