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

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 件のコメント

KSSV
KSSV 2022 年 1 月 6 日
You have not shown us the values of x.

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2022 年 1 月 6 日

1 投票

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 件のコメント

cikalekli
cikalekli 2022 年 1 月 6 日
編集済み: cikalekli 2022 年 1 月 6 日
Thanks and What does it mean "1 step increasing".
As far as I understood that I wrote -5:0.1:5 does it make 1 step?
Or Am I wrong sir?
For instance if we would want to 5 step increasing. What would we change inside it please?
cikalekli
cikalekli 2022 年 1 月 6 日
編集済み: cikalekli 2022 年 1 月 6 日
I mean for 5 step increasing, did I have to write like -5 : 0.5 : 5 ?
KSSV
KSSV 2022 年 1 月 6 日
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 2022 年 1 月 6 日
Your explanation was so fluently perfect.
I am appreciated with your help.
Bless you...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 1 月 6 日

コメント済み:

2022 年 1 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by