I keep getting "Array indices must be positive integers or logical values."
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
clear;clc
x = .993 : 0.01 : 1.283;
for n = 1 :1: length(x)
f(x) = 7*x(n)^3 - 2*x(n)^2 + 7*x(n) - 14;
g(x) = -19*x(n)^3 + 3*x(n)^2 + 16*x(n) + 8;
end
plot(x,f,'+r',x,g,'-.b')
xlabel('x values')
ylabel('f(x) and g(x) values')
legend('f(x)','g(x)')
I keep getting:
Array indices must be positive integers or logical values.
Error in (line 9)
f(x) = 7*x(n)^3 - 2*x(n)^2 + 7*x(n) -14;
Please help
0 commentaires
Réponses (3)
Sulaymon Eshkabilov
le 27 Nov 2020
Modifié(e) : Sulaymon Eshkabilov
le 27 Nov 2020
clearvars;clc
x = .993 : 0.01 : 1.283;
for n = 1 :length(x)
f(n) = 7*x(n)^3 - 2*x(n)^2 + 7*x(n) - 14; % Index has to be n
g(n) = -19*x(n)^3 + 3*x(n)^2 + 16*x(n) + 8; % Index has to be n
end
plot(x,f,'+r',x,g,'-.b')
xlabel('x values')
ylabel('f(x) and g(x) values')
legend('f(x)','g(x)')
Andrei Bobrov
le 27 Nov 2020
x = (.993 : 0.01 : 1.283)';
f = polyval([7;-2;7;-14],x);
g = polyval([-19; 3; 16; 8],x);
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!