Array Indices Must Be Positive Values
1 view (last 30 days)
Show older comments
Hello, I am trying to compute a value, v_y0. This value uses negative variables and should return a negative value. I don't understand how to assign the variables so I don't get the "array indices must be a positive integer" error. Total beginner here.
% given values
mu = 62750.28; % nm
R_e = 3443.15; % miles
h_a = 317; % nm
h_p = 317; % nm
t_t = 4320; % seconds
x_0 = 0; % feet
y_0 = -48608.924; % feet
% calculate semimajor axis (nm)
a = (h_a + h_p + 2*R_e)/2;
% calculate mean angular motion (rad/sec)
n = sqrt(mu/(a^3));
% calculate s & c
s = sin(n*t_t);
c = cos(n*t_t);
% calculate velocity in y direction
v_y0 = @(y_0)((6*x_0(n*t_t)-s)-y_0)*n*s-2*n*x_0(4-3*c)*(1-c)/(4*s-3*n*t_t)*s+4*((1-c)^2);
0 Comments
Answers (1)
Star Strider
on 12 Jul 2020
The problem is:
v_y0 = @(y_0)((6*x_0(n*t_t)-s)-y_0)*n*s-2*n*x_0(4-3*c)*(1-c)/(4*s-3*n*t_t)*s+4*((1-c)^2);
↑ ← HERE ↑ ← HERE
Since ‘x_0’ is a scalar, in the absence of a multiplication (or other) operator, that is considered to be a subscript reference. (Even if it had a legitimate positive integer value, any value greater than 1 would throw an error.) Supply the appropriate operator and the problem should resolve. Note that it may be necessary to use element-wise multiplication (.*) and division (./) for your code to run without error.
.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!