Why am I getting the error of "Array indices must be positive integers or logical values." in the f(x) line?

1 view (last 30 days)
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))

Accepted Answer

madhan ravi
madhan ravi on 1 Oct 2020
Edited: madhan ravi on 1 Oct 2020
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)
  4 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by