Why doesn't this matlab code work?!

1 回表示 (過去 30 日間)
Aryo Aryanapour
Aryo Aryanapour 2021 年 4 月 19 日
コメント済み: Aryo Aryanapour 2021 年 4 月 20 日
>> 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

採用された回答

the cyclist
the cyclist 2021 年 4 月 20 日
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 件のコメント
Aryo Aryanapour
Aryo Aryanapour 2021 年 4 月 20 日
Thank you very much
it works now

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by