I want to plot y = (3.5^(-.5x))*cos(6x) for x= -2 to x= 4 with interval of 0.01 without using for loop.
Following is the code I am writing:
clc
x = [-2:.01:4];
y = (3.5.^(-.5*x))*(cos(6*x));
plot(x,y);
But I recieve this error
Error using *
Inner matrix dimensions must agree.

 Akzeptierte Antwort

Aviel Moos
Aviel Moos am 23 Jul. 2019
Bearbeitet: Aviel Moos am 23 Jul. 2019

4 Stimmen

You need to use elementwise multimplication.
let look at this:
A = (3.5.^(-.5*x)); % Here you will get a vector with 601 elements
B = (cos(6*x)); % Here you will get also a vector with 601 elements
You cannot just multiply, You need to multiplay each element in place K of A with element in place K of B.
So just replace:
y = (3.5.^(-.5*x))*(cos(6*x));
with this:
y = (3.5.^(-.5*x)).*(cos(6*x));

Weitere Antworten (2)

Adam Danz
Adam Danz am 23 Jul. 2019

2 Stimmen

y = (3.5.^(-.5*x)).*(cos(6*x));
% ^ dot

7 Kommentare

Malik Sheraz  Nazam
Malik Sheraz Nazam am 23 Jul. 2019
Thank you :D
Adam Danz
Adam Danz am 23 Jul. 2019
There must be huge delays in server synchronization. There was 6 min between the first and second answer and one more minute for the 3rd. I certainly didn't see any answers prior to the quick 1-liner I posted. I wonder if madhan ravi saw any.
madhan ravi
madhan ravi am 23 Jul. 2019
Bearbeitet: madhan ravi am 23 Jul. 2019
As I noticed in the activity feed the answer you & I gave were at the same time, but yours were a millisecond quicker so yours came up first. The 6 mins was delta between mine and the accepted if it's what you mean.Screen Shot 2019-07-23 at 9.24.53 PM.png
Screen Shot 2019-07-23 at 9.25.01 PM.png
Adam Danz
Adam Danz am 23 Jul. 2019
The time stamps on the recent activity feed shows 15:14 (Moos' answer), 15:09 (for our ans'). I'm not sure how you're measuring milliseconds. Accepted answer at 15:16. In any case, I certainly did not see an answer despite the ~7min following the first answer.
madhan ravi
madhan ravi am 23 Jul. 2019
We are saying the same point in fact :)
Malik Sheraz  Nazam
Malik Sheraz Nazam am 26 Jul. 2019
I wish I had option to accept all the answer.
You both made life easier for me.
Thanks :D
Adam Danz
Adam Danz am 26 Jul. 2019
Bearbeitet: Adam Danz am 26 Jul. 2019
I'm just here and help out and learn a lot in the process. Accepted answers and votes are quantitative measures of skill but your appreciation is the qualitative feedback that has a longer lasting positive effect.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by