Borrar filtros
Borrar filtros

Index exceeds the number of array elements - water balance for euler loop

1 visualización (últimos 30 días)
NOtway
NOtway el 16 de Oct. de 2022
Respondida: Torsten el 16 de Oct. de 2022
I am constructing a water balance within a euler loop
for i=1:nt
time(i+1) = time(i) + dt;
% Determine lake overflow for each timestep
if V(i) + RAINFALL(i+1) - EVAP(i+1) >= V_max
Overflow(i+1) = V(i) + RAINFALL(i+1) - EVAP(i+1) - V_max;
else
Overflow(i+1) = 0;
end
Where V(i) is:
dV(i) = (RAINFALL(i) * A_catch * C / 1000) - Overflow(i) - (EVAP(i) * A / 1000); % units = m3
V(i+1) = V(i) + dt * dV(i); % volume lake in m3
The Overflow, RAINFALL and EVAP must all be applied to the same timestep (ie water overflows at the same time the lake capacity is exceeded, not in the next timestep)
However, I am getting the error "Index exceeds the number of array elements. Index must not exceed 3650"
The RAINFALL and EVAP data are both stored in 1x3650 interpolated vectors that have been extracted from an excel sheet
[date, t, Rainfall, Evap, I_t] = readvars("BOM_Data.xlsx"); %load daily data
%define desired timestep (10 points per day)
dt = 0.1; % step size (days)
time = 1:dt:(size(t,1)+0.9); % the range of time (days) (1.0 t0 365.9)
%interpolated vectors
RAINFALL = interp1(t,Rainfall,time);
EVAP = interp1(t,Evap,time);
Any suggested workarounds for getting this water balance to run? I assume the error is due to using i+1 in the water balance eq's, but I'm not sure how else to make sure that the overflow is applied in the correct timesteps.

Respuestas (1)

Torsten
Torsten el 16 de Oct. de 2022
Replace
for i=1:nt
by
for i=1:nt-1

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by