what is wrong?

3 ビュー (過去 30 日間)
IOANNA B
IOANNA B 2020 年 10 月 21 日
編集済み: Chenguang Yan 2020 年 10 月 21 日
i want to plot the function f(x)=sin(x)*cos(2*x)+1 , xe[-3,3].
my code is:
x=-3:0.1:3
y=sin(x)*cox(2*x)+1
plot(x,y)
Can you please help me? I'm new in MatLab programming and i have no idea what's wrong. Thank you.

回答 (3 件)

KSSV
KSSV 2020 年 10 月 21 日
編集済み: KSSV 2020 年 10 月 21 日
x=-3:0.1:3
y=sin(x).*cos(2*x)+1 ; % element by element multilication
plot(x,y)

Stephan
Stephan 2020 年 10 月 21 日
編集済み: Stephan 2020 年 10 月 21 日
Typo - it is cos instead of cox, and the usage of '.*' elementwise multiplication
x=-3:0.1:3
y=sin(x).*cos(2*x)+1
plot(x,y)

Chenguang Yan
Chenguang Yan 2020 年 10 月 21 日
編集済み: Chenguang Yan 2020 年 10 月 21 日
  1. Misspelling : cox -> cos
  2. * (Matrix multiplication) -> .* (Multiplication)
Try this:
x = -3:0.1:3
y = sin(x).*cos(2*x)+1
plot(x,y)
Or use fplot()
syms x
y = sin(x).*cos(2*x)+1
fplot(y,[-3,3])

カテゴリ

Help Center および File ExchangeSpecial Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by