Plot will not show lines

2 vues (au cours des 30 derniers jours)
Christina Allen
Christina Allen le 2 Mar 2021
Commenté : KSSV le 2 Mar 2021
I'm trying to show multiple lines on a graph but the lines do not show up on the figure.
x = [-0.923 : 0.01 : -0.633] ;
for n = 1 : 1 : length(x)
f(n) = 16*x(n)^3 - 13*x(n)^2 + 12*x(n) + 15
g(n) = -7*x(n)^3 - 6*x(n)^2 + 4*x(n) - 6
end
plot(x,f(n), x,g(n))
ylabel('f(x) and g(x)')
xlabel('x values')
  1 commentaire
KSSV
KSSV le 2 Mar 2021
  1. Read about element by element operations.
  2. You are plotting only one point i.e n = length(x).
  3. You have not initalized f, g

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 2 Mar 2021
Modifié(e) : KSSV le 2 Mar 2021
x = -0.923 : 0.01 : -0.633 ;
f = 16*x.^3 - 13*x.^2 + 12*x + 15 ;
g = -7*x.^3 - 6*x.^2 + 4*x - 6 ;
plot(x,f, x,g)
ylabel('f(x) and g(x)')
xlabel('x values')
  2 commentaires
Christina Allen
Christina Allen le 2 Mar 2021
thank you!! I needed to label the vertical components of my plot as f and g, instead f(n) and g(n).
KSSV
KSSV le 2 Mar 2021
Read about label and legend.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by