what is wrong?

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.

Risposte (3)

KSSV
KSSV il 21 Ott 2020
Modificato: KSSV il 21 Ott 2020

0 voti

x=-3:0.1:3
y=sin(x).*cos(2*x)+1 ; % element by element multilication
plot(x,y)
Stephan
Stephan il 21 Ott 2020
Modificato: Stephan il 21 Ott 2020

0 voti

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 il 21 Ott 2020
Modificato: Chenguang Yan il 21 Ott 2020

0 voti

  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])

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Tag

Richiesto:

il 21 Ott 2020

Modificato:

il 21 Ott 2020

Community Treasure Hunt

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

Start Hunting!

Translated by