How do I make the x-axis go to infinity so my graph can repeat?

62 vues (au cours des 30 derniers jours)
Caitlin Darling
Caitlin Darling le 12 Juil 2019
Hey guys! So i am trying to graph this formula:
y=cos(2*pi*z*n/d)
The graph is supposed to be repetitive so I was wondering if there was anyway I could make the x-axis (Z) go to infinity both ways. Right now, I only know how to graph by setting limits on the x-axis when coding. Here's what it currently looks like:
I tried inf , but that did not work. Also, n and d are constants. Thanks in advance!
  2 commentaires
Walter Roberson
Walter Roberson le 12 Juil 2019
Oddly it is permitted to use xlim with inf as the upper limit. The effect is similar to setting xlimmode to auto: it determines the limit according to the data plotted.
David K.
David K. le 12 Juil 2019
I'm not entirely certain what it is you want. If you want the plot to show the repetetive nature you may want to increase the bounds of your z variable. If you just want the x-axis to indicate that the plot continues to infinity, you could try manually setting the x-axis with xticklabels:
xticklabels({'-\infty','-20','-10','0','10','20','\infty'})
Not sure what it is you exactly want though.

Connectez-vous pour commenter.

Réponses (2)

Samatha Aleti
Samatha Aleti le 17 Juil 2019
Hi,
Specifying XLim property as "“Inf has similar effect as auto mode. However, you can view the plot for large range values (fixed- values) of X-Axis by specifying large finite values. Here is an example :
% Get handle to current axes
ax = gca;
% Specify XLim
ax.XLim = [-10^5 10^5];

Nikita khapate
Nikita khapate le 4 Oct 2020
x = -inf: 0.1 : 2;
y = 2*(x.^2) + 3*(x) + 4;
plot(x,y)
hold on
x = 2 :0.1:2;
y = 0;
plot(x,y)
hold on
x = 2.1 : 0.1 : inf;
y = -2*(x.^2) + 3*(x) -4;
plot(x,y)
hold off
  1 commentaire
Walter Roberson
Walter Roberson le 4 Oct 2020
>> x = -inf: 0.1 : 2;
Requested array exceeds the maximum possible variable size.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by