How do I graph the function f(x) = cos^2(x) - sin^2(x) over the interval [-2pi,2pi] and use 100 points in the domain?
28 views (last 30 days)
Show older comments
Mahammed Ali
on 23 Feb 2017
Commented: Image Analyst
on 25 Sep 2023
graph
5 Comments
Janaki
on 25 Sep 2023
Plot the function f(x) = sin^2(x)cos(2x) and its derivative, both on the same plot, for 0 lessthanorequalto x lessthanorequalto 2pi. Plot the function with a solid line, and the derivative with a dashed line. Add a legend and label the axes.
Image Analyst
on 25 Sep 2023
@Janaki, This looks like a homework problem. Please start your own question for this homework if you can't figure out how to say
x = linspace(0, 2 * pi, 1000);
f = sin(x).^2 * cos(2 * x);
plot(f, x, 'b-');
It's really quite simple so I'm guessing you never took the MATLAB onramp training. Please invest 2 hours of your time here so that you don't need to ask about every simple thing like this: MATLAB Academy - Free 2 hour training
If you have any questions ask your instructor or read the link below to get started:
Obviously we can't give you the full solution because you're not allowed to turn in our code as your own.
For the derivative, I'd just compute the formula analytically using techniques: https://web.iit.edu/sites/web/files/departments/academic-affairs/academic-resource-center/pdfs/product_quotient_rule.pdf then plot it with plot.
Accepted Answer
Image Analyst
on 23 Feb 2017
Your formula
y = cos(x).^2 - sin(x).^2
is correct. What you're missing is how to create x. Hint: use the linspace() function.
0 Comments
More Answers (2)
Hina Shaheen
on 14 Sep 2020
f(x)= cos^2(x)-sin^2(x) over the interval -2pie, 2pie
1 Comment
Image Analyst
on 14 Sep 2020
Edited: Image Analyst
on 3 Jun 2021
Hina, I already answered it above in my Answer. Perhaps you overlooked it. Here is what you would have gotten:
x = linspace(-2*pi, 2*pi, 100);
fx = cos(x) .^ 2 - sin(x) .^ 2;
plot(x, fx, 'b-', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', 20);
ylabel('f(x)', 'FontSize', 20);

mostafa mohamad
on 3 Jun 2021
t=1:5
y=2*cos(2*pi*1400*t
)
1 Comment
Image Analyst
on 3 Jun 2021
Not sure how this is an answer to plotting f(x) = cos^2(x) - sin^2(x) over the interval [-2pi,2pi].
Like I said, the solution is
x = linspace(-2*pi, 2*pi, 100);
fx = cos(x) .^ 2 - sin(x) .^ 2;
plot(x, fx, 'b-', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', 20);
ylabel('f(x)', 'FontSize', 20);
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!