Receiving mtimes error for passing vector through a function and I don't know why. Help?

 Akzeptierte Antwort

You need to use .*
y = exp(2*sin(0.4*x))*5 .* cos(4*x);

2 Kommentare

thank you! I was putting after the exp().
Why does it need to be after the 5?
You can think of anything before 5 is a row vector and then everything after 5 is another row vector. To multiply two vectors together, you need the .* there. If you put it in front of 5, since at that time MATLAB is evaluating a multiplication between a vector and a scalar, it doesn't help. Once it finishes 5, it still encounter the same situation. If you have to put it in front of 5, then you need to group 5 and cos(4*x) together with a parenthesis.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by