Graphing the sine graph

Hey Guys, I am currently learning how to use Matlab and I have a problem that I am struggling with. I am struggling to graph the function y = sin^2(t) on the interval t ∈ [0,2π]. Can you please help me this?

5 Comments

Dyuman Joshi
Dyuman Joshi on 29 Feb 2024
Edited: Dyuman Joshi on 29 Feb 2024
Please share the code you have written yet and state the issue you are facing.
The syntax for y = sin^2(t) in MATLAB is
y = sin(t).^2
Hope that helps.
First things first, make sure to bookmark the Help Center, and then search for the keyword 'plot'. You will find the relevant information at this URL: https://www.mathworks.com/help/matlab/ref/plot.html.
It's always a good idea to start by searching in the Help Center before seeking technical assistance, unless the problem is highly specific and no relevant examples can be found.
@Sam Chak Okay thank you. I will make use of it.
If you are just getting started with Matlab, I would highly recommend that you take a couple of hours to go through the free online tutorial: Matlab Onramp

Sign in to comment.

 Accepted Answer

t = linspace(0,2*pi,1000);
y = sin(t).^2;
plot(t,y);

5 Comments

Dyuman Joshi
Dyuman Joshi on 29 Feb 2024
Edited: Dyuman Joshi on 29 Feb 2024
Please don't do obvious homework questions on Answers, when no effort has been shown. This does not help the student, who learns nothing more than to post all of their homework problems on the site, hoping they will find someone willing to do their thinking and work for them. Worse that that, it convinces the next student who comes along to do the same.
If you want to help, then find a way to push the student in the right direction. But posting a complete solution does far more harm than good.
To be honest, some of these questions remind me at the time when I got my first PC-Matlab license in the late 80s. But there was no one I can ask, no www and no mailing list. Hence, it took a long time until I got familiar with Matlab, comming from F77. So I'm not as strict with novices and I'm indulge them.
Thank you, @Alexander. @Dyuman Joshi You're right, I was frustrated because I was trying to figure it out for a long time without reaching any solution. Next time I will make it a point to try reach some form of a solution.
Cheers
@Dakalo, Can you enter the code (click this icon ) and run it here (click this icon )?
A grey field will appear so that you can type out the plotting code. You should also learn about labeling and display trick for repeating decimals such as .

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Asked:

on 29 Feb 2024

Commented:

on 29 Feb 2024

Community Treasure Hunt

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

Start Hunting!