Visually displaying a value going to infinity in matlab

I am trying to reproduce the Dirac Delta function:

Dirac Delta Function

my code is:

x = -30:1:30;
y = zeros(1,numel(x)); %sets all values initially to zero
y(x==0)= inf; % the point corresponding to x=0 is set to inf
plot(x,y,'d')
axis([-40 40 0 inf])

My code produces:

My figure

+4
source share
3 answers

You can do this with stem, by pointing it 'Marker'as an up arrow ...

% Open figure
figure;
% Blue stem plot at x=0, to y=75. Marker style is up arrow
stem(0, 75,'color','b','linewidth',2,'marker','^')
% Add infinity label at x=0, y = 82 = 75 + fontsize/2, where we plotted up to 75
text(0,82,'∞','FontSize',14)
% Set axes limits
xlim([-40,40])
ylim([0,90])

You can see the graph here, but see the change below for the improved version.

Please note, of course, you must choose a y value that is large compared to any other data on the chart. In this example, I chose 75 to get closer to your desired example. MATLAB cannot construct a value in inf, because, well, where does infinity sit on the y axis?


: , y '≈', . xlim ylim axis y, , :

stem(0, 80,'color','b','linewidth',2,'marker','^')
text([-42,0,38], [80,87,80], {'≈','∞','≈'}, 'Fontsize', 14)
axis([-40, 40, 0, 100])
yticks(0:20:60)

plot2

+9

, y . y , . , [min_x max_x min_y max_y], y(x==0) = max_y*10.

:

x = -30:1:30; min_x = min(x) - 10; max_x = max(x) + 10;
y = zeros(1,numel(x)); 
% compute values of y here
% ...
min_y = min(y) - 10; max_y = max(y) + 10;
y(x==0)= 10 * max_y; 
plot(x,y,'d');
axis([min_x max_x min_y max_y]);
+3

Use the tick property on the Matlab plot as described below.

screenshot

-1
source

Source: https://habr.com/ru/post/1693905/


All Articles