Why am I getting "Array indices must be positive integers or logical values"?

1 view (last 30 days)
I'm currently trying to plot a function from x=0 to 1 and the function "var" keeps coming up with the error code "Array indices must be positive integers or logical values". Any suggestions? Thank you
a=1;
n=1;
x=0:0.01:1;
psi=(2/a).^0.5.*sin((n*pi*x)/a);
N=(10.816).^0.5;
var=N(x.^(0.862)-x.^(2.862));

Answers (1)

Adam Danz
Adam Danz on 9 Dec 2019
Edited: Adam Danz on 10 Dec 2019
This line below implies that you're trying to index values from an array N where the index values must be positive integers or logicals.
N(x.^(0.862)-x.^(2.862))
Clearly the "indices" do not meet those requirements.
My guess is that the intention is to multiply N by those values.
var = N .* (x.^(0.862)-x.^(2.862));
% ^^

Categories

Find more on Operators and Elementary Operations 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!