Code for an equation

2 vues (au cours des 30 derniers jours)
Malik Sheraz  Nazam
Malik Sheraz Nazam le 23 Juil 2019
Modifié(e) : Adam Danz le 26 Juil 2019
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.

Réponse acceptée

Aviel Moos
Aviel Moos le 23 Juil 2019
Modifié(e) : Aviel Moos le 23 Juil 2019
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));
  1 commentaire
Malik Sheraz  Nazam
Malik Sheraz Nazam le 23 Juil 2019
Thank you :D

Connectez-vous pour commenter.

Plus de réponses (2)

Adam Danz
Adam Danz le 23 Juil 2019
y = (3.5.^(-.5*x)).*(cos(6*x));
% ^ dot
  7 commentaires
Malik Sheraz  Nazam
Malik Sheraz Nazam le 26 Juil 2019
I wish I had option to accept all the answer.
You both made life easier for me.
Thanks :D
Adam Danz
Adam Danz le 26 Juil 2019
Modifié(e) : Adam Danz le 26 Juil 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.

Connectez-vous pour commenter.


madhan ravi
madhan ravi le 23 Juil 2019
  1 commentaire
Malik Sheraz  Nazam
Malik Sheraz Nazam le 23 Juil 2019
Thanks :D

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by