What am i doing wrong in this code

i am ploting these graphs in matab ...............i have written the equations as given in the book but the plots are not coming as they are shown in the book .............am i doing any thing wrong.............the attached file is the output of my code on matlab

clear all
clc
t=[0 1 2]
x=[1 1 0]
subplot(5,1,1)
plot(t,x)
xlabel('time axis')
ylabel('amplitude')
title('                                     x(t)')
grid on
axis([-2 5 0 2])
x1=(t+1)
subplot(5,1,2)
plot(x1,x)
xlabel('time axis')
ylabel('amplitude')
title('                                     x(t+1)')
grid on
axis([-2 5 0 2])
x2=(-t+1)
subplot(5,1,3)
plot(x2,x)
xlabel('time axis')
ylabel('amplitude')
title('                                     x(-t+1)')
grid on
axis([-2 5 0 2])
xt=3*t
x3=(xt/2)
subplot(5,1,4)
plot(x3,x)
xlabel('time axis')
ylabel('amplitude')
title('                                     x(3*t)/2)')
grid on
axis([-2 5 0 2])
x4=x3+1
subplot(5,1,5)
plot(x4,x)
xlabel('time axis')
ylabel('amplitude')
title('                                     x((3*t)/2)+1)')
grid on
axis([-2 5 0 2])

 Accepted Answer

Looks like you have a piecewise function at the very beginning. If you have Symbolic Toolbox, it will be really easy for you to implement it and plot whatever you want. Try this:
syms t
x(t)=piecewise(t>=0 & t<=1,1,t>1,-t+2);
figure(1)
a=0;b=1;
t=0-a:0.01:2-a;
plot(b^-1*t,x(b*t));grid on;title('x(t)')
figure(2)
a=1;b=1;
t=0-a:0.01:2-a;
plot(b^-1*t,x(b*t+a));grid on;title('x(t+1)')
figure(3)
a=1;b=1;
t=0-a:0.01:2-a;
plot(sort(-(b^-1*t),'ascend'),x(-(b*t)+a));grid on;title('x(-t+1)')
figure(4)
a=0;b=1.5;
t=0-a:0.001:2-a;
plot(t,x(b*t+a));grid on;title('x((3/2)*t)')
figure(5)
a=1;b=1.5;
t=0-a:0.01:2-a;
plot(t,x(b*t+a));grid on;title('x((3/2)*t+1)')

1 Comment

not working sir there is a problem in the 2nd line and i am not able to figure it out because i have never used piecewise

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 7 Mar 2018

Edited:

on 7 Mar 2018

Community Treasure Hunt

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

Start Hunting!