I get an error and what caused it? - Function Plotting

1 vue (au cours des 30 derniers jours)
cikalekli
cikalekli le 6 Jan 2022
Commenté : cikalekli le 6 Jan 2022
I get an error. What caused it and how do I fix it?
Here my code:
t = -5:0.1:5;
y = ((2.*cos(x)+exp(-0.4.*x))./(0.2.*x+exp(-0.2.*x))) + ((4.*x)./3);
plot(t,y);
Edit: Typo correction.
  1 commentaire
KSSV
KSSV le 6 Jan 2022
You have not shown us the values of x.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 6 Jan 2022
Are you looking for this?
x = -5:0.1:5;
y = ((2.*cos(x)+exp(-0.4.*x))./(0.2.*x+exp(-0.2.*x))) + ((4.*x)./3);
plot(x,y);
  4 commentaires
KSSV
KSSV le 6 Jan 2022
You can just print the values and see.
a = -5:0.1:5 ; % this creates numbers between -5 and 5 with step size 0.1
diff(a)
ans = 1×100
0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000
Also have a look on linspace.
b = linspace(-5,5,5)
b = 1×5
-5.0000 -2.5000 0 2.5000 5.0000
If you want 5 as the step/ difference. YEs use:
c = -5:5:5
c = 1×3
-5 0 5
cikalekli
cikalekli le 6 Jan 2022
Your explanation was so fluently perfect.
I am appreciated with your help.
Bless you...

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by