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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abdelrahman Adel
le 5 Déc 2023
Réponse apportée : Walter Roberson
le 6 Déc 2023
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
0 commentaires
Réponse acceptée
Walter Roberson
le 6 Déc 2023
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Boundary Conditions 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!