How do you graph y = cosx and y = 5 + cosx over the interval [0,4pi]?
I also want to use the command "ylim([-2,7]) in order to view the graph clearly.
I just installed Matlab and it is my first time using this software. Thanks

1 Kommentar

Joseph Wilson
Joseph Wilson am 3 Dez. 2020
Will need to create a array of x values to plot against. Something like x = 0:pi/4:4*pi;... Might need a tighter interval (middle value in equation) for a smoother plot so maybe pi/12 or smaller.
Will need to create two equations with those values: y1 = cos(x); y2=5+cos(x);
Use plot command with those arrays. 2 ways to do this:
1: plot(x,y1,x,y2);
2: plot(x,y1); hold on; plot(x,y2); This method is usually prefered for ease of changing line styles and colors.
Type "doc plot' into command window and hit enter for more information on line styles and colors
lastly just use ylim([-2,7]); to change the limits of the graph.
hold on makes sure it plots on the same graph without erasing previous plotting.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

VBBV
VBBV am 3 Dez. 2020
Bearbeitet: Rik am 3 Dez. 2020

0 Stimmen

x = 0:0.01:4*pi;
plot(x,cos(x));hold on;
plot(x,5+cos(x));
ylim([-2 7])

1 Kommentar

Rik
Rik am 3 Dez. 2020
If you're using the legacy editor (e.g. because you are on mobile) you can start a code block with two space after a blank line (or start the first line with two spaces).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rik
Rik am 3 Dez. 2020

0 Stimmen

The Onramp tutorial will guide you through problems like this and will teach you the Matlab basics.

1 Kommentar

Eric Andre
Eric Andre am 3 Dez. 2020
great ill look into it right now, thanks!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Dez. 2020

Kommentiert:

am 3 Dez. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by