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

 Accepted Answer

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

2 Comments

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.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!