MATLAB: Am I getting “Array indices must be positive or integers values”

integersMATLABsine function

This is a sine function, which should give me positive and negative values.
syms t
t = 0:0.02:2;
om = 10;
% Steady State Response
up(t)=(100/(400-om^2))*sin(om*t);
plot(t,up(t))
xlabel('Time (sec)')
ylabel('Displacement (in)')
title('Displacement vs Time Response')
Array indices must be positive integers or logical values.
Error in HW5plot (line 6)
up(t)=(100/(400-om^2))*sin(om*t);

Best Answer

Rhe reason is that ‘up(t)’ was being interpreted as an indexing operation rather than a function call, and ‘t’ are not all positive integers. The plot call was also inappropriate.
Try this:
syms t
om = 10;
% Steady State Response
up(t)=(100/(400-om^2))*sin(om*t);
figure
fplot(up, [0 2])
xlabel('Time (sec)')
ylabel('Displacement (in)')
title('Displacement vs Time Response')
.