Why doesn't this matlab code work?!

2 vues (au cours des 30 derniers jours)
Aryo Aryanapour
Aryo Aryanapour le 19 Avr 2021
Commenté : Aryo Aryanapour le 20 Avr 2021
>> x = -5:1:5;
>> y = exp(x)*(x.^3-5*x.^2+5*x+1);
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix
matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Related documentation
>> plot(x,y)
Unrecognized function or variable 'y'.
thank you

Réponse acceptée

the cyclist
the cyclist le 20 Avr 2021
You missed a spot where you needed an element-wise operation, multiplying the exp(x) by the other term:
x = -5:1:5;
y = exp(x).*(x.^3-5*x.^2+5*x+1);
  1 commentaire
Aryo Aryanapour
Aryo Aryanapour le 20 Avr 2021
Thank you very much
it works now

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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!

Translated by