Plotting x(2t+2) if x(t) is defined as an anonymous function

I have to plot the function
g = @(t) exp(-t/2)*cos(2*t*pi/3)*u(t);
for g(2t+2). I tried a couple things but I either get a blank graph or just a straight line. The only way it works is if I actually switch all the ts into (2t+2) which is excessivly time consuming

回答 (1 件)

William Rose
William Rose 2022 年 10 月 5 日
編集済み: William Rose 2022 年 10 月 5 日

1 投票

[edit: correct typos (no typos in the code) ]
You need to define u.
If you define the muliplications inside g() with ".*" instead of "*", then you can pass a vector of times to g and get an answer
Given
t=0:.2:10;
u = @(t) double(t>=0);
g = @(t) exp(-t/2).*cos(2*t*pi/3).*u(t);
plot(t,g(t))
As for 2*t+2:
hold on; %preserve existing plot
plot(t,g(2*t+2),'-r');
Works.

2 件のコメント

Yakov
Yakov 2022 年 10 月 5 日
That seemed to work, Thanks for the help!
William Rose
William Rose 2022 年 10 月 6 日
@Yakov, you're welcome. Please accept the answer if you deem it sufficient.

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

カテゴリ

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

質問済み:

2022 年 10 月 5 日

コメント済み:

2022 年 10 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by