How to plot this function?

回答 (2 件)

Star Strider
Star Strider 2017 年 1 月 28 日

0 投票

It’s straightforward:
t = linspace(0, 99);
f = @(t) (exp(-t).*(exp(-floor(-t)) - 1))/(exp(1) - 1);
figure(1)
plot(t, f(t), '-pg')
grid
See the documentation for the plot function, and Function Basics (link) to understand the anonymous function.

4 件のコメント

qpei9f dkaslfjl
qpei9f dkaslfjl 2017 年 1 月 28 日
Thank you. How do I reduce the scale?
Star Strider
Star Strider 2017 年 1 月 28 日
My pleasure.
You can adjust the range of ‘t’ by changing the first two arguments of the linspace function, and the number of elements in the vector it returns by specifying that in the third argument. So to set ‘t’ to be a vector of 500 elements going from -5 to +10, you would define it as:
t = linspace(-5, 10, 500);
To adjust the range of the axes in the plot, see the documentation for the axis (link) function. It will allow you to set the limits for the axes. So to set the x-axis to go from 0 to 10 and the y-axis to go from 0.5 to 0.6, after the plot call, you would set the axis limits as:
axis([0 10 0.5 0.6])
qpei9f dkaslfjl
qpei9f dkaslfjl 2017 年 1 月 30 日
Again, thanks a lot.
Star Strider
Star Strider 2017 年 1 月 30 日
My pleasure.

サインインしてコメントする。

Image Analyst
Image Analyst 2017 年 1 月 28 日

0 投票

Try this:
t = linspace(-4, 15, 1000);
y = (exp(-t) .* (exp(-1) .^ floor(-t) - 1)) ./ (exp(1) - 1);
plot(t, y, 'LineWidth', 2);
grid on;
fontSize = 20;
xlabel('t', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
ax = gca
ax.YAxisLocation = 'origin'
ax.XAxisLocation = 'origin'

1 件のコメント

qpei9f dkaslfjl
qpei9f dkaslfjl 2017 年 1 月 28 日
Thanks a lot. Seems it is periodic as I hoped.

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2017 年 1 月 28 日

コメント済み:

2017 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by