Plotting discrete piecewise funtion

10 visualizaciones (últimos 30 días)
Patrick Struszczyk
Patrick Struszczyk el 16 de Oct. de 2020
Comentada: Patrick Struszczyk el 16 de Oct. de 2020
I have a piecewise function as follows:
f(t) = 0 for t < 0
t for 0 ≤ t < 1
and e −t+1 for t ≥ 1
I'm attempting to sketch x[k]=f(0.5k) with k being counting numbers.
x2=piecewise(t<0,0,0<=t<1,t,exp(-t+1));
x3=x2.*(2.*k);
subplot (4,1,4)
stem(x3)
title('3b.3')
  1 comentario
Patrick Struszczyk
Patrick Struszczyk el 16 de Oct. de 2020
I keep getting the error :
Error using stem (line 40)
Unable to convert expression into double array.
How can I fix this?

Iniciar sesión para comentar.

Respuestas (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 16 de Oct. de 2020
Editada: Asad (Mehrzad) Khoddam el 16 de Oct. de 2020
piecewise function is for symbolic toolbox.
You can use:
t=0:0.1:5.0;
f= t.*(t>=0 & t<1 ) + exp(-t+1).*(t>=1);
plot(t,f);

Categorías

Más información sobre Elementary Math en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by