How do I create function that is defined by itself?

3 Ansichten (letzte 30 Tage)
Hjalmar Stenberg
Hjalmar Stenberg am 22 Apr. 2021
Beantwortet: Pratyush Roy am 27 Apr. 2021
I need help creating this function. I have defined x(t) as
x = @(t) t.*((t>=0)&(t<1))+(0.5+0.5.*cos(2*pi*t)).*((t>=1)&(t<2))+(3-t).*((t>=2)&(t<3));
The end result should look like this

Antworten (1)

Pratyush Roy
Pratyush Roy am 27 Apr. 2021
Hi,
As per the equations mentioned above, the function is a periodic one with a period of 4. You can refer to code snippet below to generate a periodic function:
x = @(t) t.*((t>=0)&(t<1))+(0.5+0.5.*cos(2*pi*t)).*((t>=1)&(t<2))+(3-t).*((t>=2)&(t<3))
duration = T;
t = 0:0.5:T; %Time interval is chosen as 0.5 in this case, user can change this value.
y = x(mod(t,4));%Period of 4
plot(t,y)
Hope this helps!

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by