MATLAB: How to sketch the following signal? x(t)= 3u(t-10)+ 4u(-t+3)-r​(t+2)+4r(t​)-2u(-t-2)​-2r(t-3)-2​u(t-4)+r(-​t-5)

...

Since the question contains both step and ramp, how to write the code for it?

Best Answer

syms u(t) r(t) x(t) t0
u(t)=piecewise(t<t0, 0, t>=t0, 1);
r(t)=piecewise(t<t0, 0, t>=t0, t-t0);
t1=-6:0.01:10;
x(t)=3*u(t-10)+4*u(-t+3)-r(t+2)+4*r(t)-2*u(-t-2)-2*r(t-3)-2*u(t-4)+r(-t-5);
x=subs(x,{t0,t},{0,t1});
plot(t1,x)
Something like this should do it. Note that I defined the input range randomly. Hope this helps.