how do I input the following commands in Matlab?

5 ビュー (過去 30 日間)
Cristian Rivera
Cristian Rivera 2022 年 4 月 12 日
回答済み: Lokesh 2023 年 9 月 25 日
I am unsure how to properly inupt the following functions into matlab x(t)= 0.01t^2 [u(t) - u(t-6)] and h(t)= cos(0.25*pi*t)[u(t+2) - u(t-2)]
  2 件のコメント
Cristian Rivera
Cristian Rivera 2022 年 4 月 12 日
is it something like x = @(t) (0.01*t^2).*double(t>=-6 & t<=1);
h= @(t) cos(.25*pi*t).*double(t>=-2 & t<=2);
Torsten
Torsten 2022 年 4 月 12 日
You don't need the "double":
x = @(t) (0.01*t^2).*(t>=-6 & t<=1);
h = @(t) cos(.25*pi*t).*(t>=-2 & t<=2);

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

回答 (1 件)

Lokesh
Lokesh 2023 年 9 月 25 日
Hi Cristian,
I understand that you want to input the functions “x(t)= 0.01t^2 [u(t) - u(t-6)]” and “h(t)= cos(0.25*pi*t)[u(t+2) - u(t-2)] into MATLAB.
The "heaviside" function available in MATLAB’s Symbolic Math Toolbox can be used to represent the unit step function ‘u(t)’.
Using anonymous functions along with the “heaviside” function, you can define the functions x(t) and h(t) in MATLAB as:
% Define x(t)
x = @(t) 0.01*t.^2.*(heaviside(t)-heaviside(t-6));
% Define h(t)
h = @(t) cos(0.25*pi*t).*(heaviside(t+2)-heaviside(t-2));
If you do not have Symbolic Math Toolbox, you can define the heaviside function manually as follows:
heaviside = @(t) (t >= 0);
I hope this resolves your issue.You can refer to the below mentioned documentation to know more about the usage of “heaviside” function and “Anonymous Functions” respectively:
Best Regards,
Lokesh

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by