Plotting a function with an array of x returns one y value

Hey all!
I am trying to plot a specific problem and cannot seem to have it plot correctly
This is currently the code in which i am using. I have tried mulitple iterations as to get it to work. I either recieve a blank plot or a straight line plot.
x = -2:0.1:16;
y = (4*cos(x))/(x + exp(-0.75*x));
plot (x,y)
Either this or
y = (4*cos(x))/(x + exp(-0.75*x));
fplot (y, [-2 16])
And yet the plot should look something like this

Réponses (1)

Stephen23
Stephen23 le 14 Fév 2023
Modifié(e) : Stephen23 le 14 Fév 2023
You won't get very far using MATLAB if you do not learn the difference between array and matrix operations:
Tip: if you are not doing linear algebra, then you probably want to use array operations.
x = -2:0.1:16;
y = (4*cos(x))./(x + exp(-0.75*x));
% ^^ RDIVIDE, not MRDIVIDE
plot (x,y)

Catégories

Produits

Version

R2022b

Tags

Question posée :

le 14 Fév 2023

Modifié(e) :

le 14 Fév 2023

Community Treasure Hunt

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

Start Hunting!

Translated by