MATLAB: Am I getting the error of “Array indices must be positive integers or logical values.” in the f(x) line

homeworkMATLAB

clear; clc
x = -1.612 : 0.01 : -1.322 ;
for n = 1:1:length(x)
f(x) = 8 * x(n)^3 - 2 * x(n)^2 - 15 * x(n) + 11 ;
g(x) = -10 * x(n)^3 + 10 * x(n) - 13 ;
end
figure(1)
plot(x,f(x), x,g(x))

Best Answer

Why on Earth do you need a loop?
x = -1.612 : 0.01 : -1.322 ;
f = 8 * x.^3 - 2 * x.^2 - 15 * x + 11 ;
g = -10 * x.^3 + 10 * x - 13 ;
figure(1)
plot(x, f, x, g)