How to plot this stepfunction

Hello,
I am trying to plot a step function can be seen below. Any help will be highly appreciated. Thank you.

回答 (1 件)

Star Strider
Star Strider 2018 年 9 月 23 日

0 投票

For the unit step function, you can use the Symbolic Math Toolbox heaviside function, or this anonymous function:
ustp = @(t) +(t>0); % Simple Unit Step Function
I leave the rest to you.
Remember to use element-wise operations for the multiplications. See the documentation page on Array vs. Matrix Operations (link) and Vectorization (link).

4 件のコメント

Younes Alawaji
Younes Alawaji 2018 年 9 月 23 日
Can you please explain more! I tried but no success can you direct me how to plot at least the first one? Appreciate any inputs!
Star Strider
Star Strider 2018 年 9 月 23 日
I will give you an illustration, and let you take it from here:
t = linspace(-10, 20, 1E+6);
f = @(t) sin(2*pi*t).*cos(2*pi*t*0.1);
figure
plot(t, f(t).*ustp(t-5))
grid
Note specifically the argument to ‘ustp’ with respect to the resulting plot.
Younes Alawaji
Younes Alawaji 2018 年 9 月 23 日
編集済み: Younes Alawaji 2018 年 9 月 23 日
Thank you for reaching back and trying your best to illustrate to me. I tried to run your sample but it gave me an error at the line: plot(t, f(t).*ustp(t-5)), it says that "ustp," does not exist. Below I have tried to plot it:
t = linespace(100, -50, 50,-150,-250,-300); %% These are the constant with the t function
u = @(t) [10, 5 , -5 , -15 , -25 , -30] ; %% the ones with the u function
plot(t,u); axis [-30 30 -100 100 ];
Is this is how to do the step function? Any inputs will be appreciated
Star Strider
Star Strider 2018 年 9 月 23 日
My pleasure.
My code is intended to illustrate how to combine the unit step function (my ‘ustp’ anonymous function) with another function to create the desired result. You cannot simply use it without modifying your code.
Also, you have to copy my ‘ustp’ function to the beginning of your script file. My code should then work.

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

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2018 年 9 月 23 日

コメント済み:

2018 年 9 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by