Filter löschen
Filter löschen

Why doesn't this matlab code work?!

1 Ansicht (letzte 30 Tage)
Aryo Aryanapour
Aryo Aryanapour am 19 Apr. 2021
Kommentiert: Aryo Aryanapour am 20 Apr. 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

Akzeptierte Antwort

the cyclist
the cyclist am 20 Apr. 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);

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by