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])

 采纳的回答

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by