MATLAB Answers

what is wrong?

1 view (last 30 days)
IOANNA B
IOANNA B on 21 Oct 2020
Edited: chenguang yan on 21 Oct 2020
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.

  0 Comments

Sign in to comment.

Answers (3)

KSSV
KSSV on 21 Oct 2020
Edited: KSSV on 21 Oct 2020
x=-3:0.1:3
y=sin(x).*cos(2*x)+1 ; % element by element multilication
plot(x,y)

  0 Comments

Sign in to comment.


Stephan
Stephan on 21 Oct 2020
Edited: Stephan on 21 Oct 2020
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)

  0 Comments

Sign in to comment.


chenguang yan
chenguang yan on 21 Oct 2020
Edited: chenguang yan on 21 Oct 2020
  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])

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!