フィルターのクリア

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 Center および File ExchangeBoundary Conditions についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by