Why am I receiving the error message "Array indices must be positive integers or logical values"?

1 次查看(过去 30 天)
Hello, I am getting stuck on computing one of the components of a model that I am working on. Attempting to compute the component u_z returns the error "Array indices must be positive integers or logical values." I am stumped on what is going wrong as the other component, u_r, is being computed and returning an array with no problems. Attached below is the code and the error:
% Define parameters
R = 5000;
r_max = 45;
z_max = 4000;
ch_o = z_max / 0.22;
ch_i = ch_o / 12.5;
sf = r_max / (0.2357 * R);
r = -2000:0.1:2000;
z = 6000;
% Plot results
plot(r, Compute_u(R, ch_o, ch_i, sf, r, z))
function u = Compute_u(R, ch_o, ch_i, sf, r, z)
u_r = ((sf * R^2)./(2 .* r)) .* (1-exp(-(r./R).^2)) .* (exp(-(z/ch_o))-exp(-(z/ch_i)));
u_z = (-(sf .* exp(-(r./R).^2))) .* (ch_i(exp(-(z/ch_i))) - ch_o(exp(-(z/ch_o))-1));
u = sqrt(u_r^2 + u_z^2);
end

采纳的回答

Jan
Jan 2022-5-18
编辑:Jan 2022-5-18
ch_i(exp(-(z/ch_i)))
ch_o(exp(-(z/ch_o))-1)
Here exp(-(z/ch_i)) and exp(-(z/ch_o))-1 are used as indices of the variables ch_i and ch_o. Are you sure that this is wanted? Both are scalars, so indexing is not useful at all. Maybe you want:
ch_i * (exp(-(z/ch_i)))
ch_o * (exp(-(z/ch_o))-1)
instead.
By the way, you can write this leaner as:
ch_i * exp(-z/ch_i)
ch_o * exp(-z/ch_o) - 1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Time Series 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by