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

1 visualización (últimos 30 días)
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))

Respuesta aceptada

madhan ravi
madhan ravi el 1 de Oct. de 2020
Editada: madhan ravi el 1 de Oct. de 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 comentarios
Gina Jarid
Gina Jarid el 1 de Oct. de 2020
Thanks this works, but I was told with the given info to begin my for-loop like this
So your for loop would begin:
x = [-1.612 : 0.01 : -1.322] ;
for n = 1 : 1 : length(x)
f(x) = 8*x(n)^3 ...
g(x) = -10*x(n)^3 ...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by