How do I multiply two trigonometric functions

Hi I am trying to multiply sin(x) by the cos(x) and graph the result. What am I doing now is not working. Can someone please explain to me what I am doing wrong? Here is my code.
x=[-2:0.5:10];
y=(sin(x))*(cos(x));
plot(x,y)

1 Kommentar

John Hart
John Hart am 4 Mai 2020
this was very helpful, thanks belleagured student .... in MSEE program

Melden Sie sich an, um zu kommentieren.

Antworten (1)

the cyclist
the cyclist am 16 Feb. 2016

8 Stimmen

You need element-wise multiplication
y=sin(x).*cos(x);

5 Kommentare

I put this in, x=[-2:0.5:10]; y=sin(x).*cos(x);
and I got:
warning: function ./test.m shadows a core library function
Star Strider
Star Strider am 16 Feb. 2016
1. To multiply trigonometric functions, another option is the Wikipedia article covering the List of Trigonometric Identities.
2. Don’t name any variables or files the same as built-in MATLAB functions. This is called ‘overshadowing’. Name your file something else. MATLAB is case-sensitive, so renaming it Test.m would be sufficient.
the cyclist
the cyclist am 17 Feb. 2016
Moved this from an "answer" from Alexander to a comment here:
I am sorry you were right. That does work. Thank you.
the cyclist
the cyclist am 17 Feb. 2016
The best form of thanks is to upvote and/or accept an answer. This rewards the contributor, and can point future users to helpful answers.
thanx. solved my problem

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 16 Feb. 2016

Kommentiert:

am 4 Mai 2020

Community Treasure Hunt

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

Start Hunting!

Translated by