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)
Mostrar comentarios más antiguos
Gina Jarid
el 1 de Oct. de 2020
Comentada: madhan ravi
el 1 de Oct. de 2020
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))
0 comentarios
Respuesta aceptada
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
madhan ravi
el 1 de Oct. de 2020
Explain to your teacher/professor preallocation is important , while using a loop.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!